home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume89 / aplictns / hyphelp.3 < prev    next >
Internet Message Format  |  1989-10-25  |  62KB

  1. Path: xanth!uakari.primate.wisc.edu!gem.mps.ohio-state.edu!apple!sun-barr!newstop!sun!swap!page
  2. From: page%swap@Sun.COM (Bob Page)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v89i189:  hyperhelp - amiga help system, Part03/03
  5. Message-ID: <126803@sun.Eng.Sun.COM>
  6. Date: 25 Oct 89 17:05:56 GMT
  7. Sender: news@sun.Eng.Sun.COM
  8. Lines: 2468
  9. Approved: page@sun.com
  10.  
  11. Submitted-by: jap@syssun.cl.msu.edu (Joe A. Porkka)
  12. Posting-number: Volume 89, Issue 189
  13. Archive-name: applications/hyphelp.3
  14.  
  15. # This is a shell archive.
  16. # Remove anything above and including the cut line.
  17. # Then run the rest of the file through 'sh'.
  18. # Unpacked files will be owned by you and have default permissions.
  19. #----cut here-----cut here-----cut here-----cut here----#
  20. #!/bin/sh
  21. # shar: SHell ARchive
  22. # Run the following text through 'sh' to create:
  23. #    helptext.h
  24. #    image.c
  25. #    indev.c
  26. #    index.c
  27. #    kludge.h
  28. #    link
  29. #    main.c
  30. #    menu.c
  31. #    move.c
  32. #    oserr.c
  33. #    print.c
  34. #    source.readme
  35. #    style.h
  36. #    tokens.c
  37. #    windows.c
  38. # This is archive 3 of a 3-part kit.
  39. # This archive created: Wed Oct 25 10:02:52 1989
  40. echo "extracting helptext.h"
  41. sed 's/^X//' << \SHAR_EOF > helptext.h
  42. X/* HyperHelp -- Copyright 1989 Joe Porkka */
  43. X
  44. X/* helptext.h  --  The structure definitions for text management stuff */
  45. X
  46. Xstruct displaylines {
  47. X    u_short offset;
  48. X    u_char length, style, color;
  49. X};
  50. Xstruct paragraph {
  51. X    u_char  *data;
  52. X    u_char indent, pindent;
  53. X    u_short length, count;
  54. X    struct displaylines *lines;
  55. X};
  56. X
  57. Xstruct    labels {
  58. X    u_char  *name;
  59. X    u_short paragraph;
  60. X    u_short line;
  61. X};
  62. X
  63. X#define DOC_FORMATED 1
  64. X#define COMWIDTH 116
  65. Xstruct textbody {
  66. X    u_char *text, *filename;
  67. X    unsigned long length;
  68. X    u_short usecount;
  69. X    struct TextAttr font;
  70. X    u_char  comment[COMWIDTH];
  71. X};
  72. X
  73. Xstruct    doc {
  74. X    u_short lab_count;
  75. X    struct labels *labs;
  76. X    u_short p_count;
  77. X    struct paragraph *p;  /* linked list of lines, formatted nicely */
  78. X    u_char linespace, flags; /* doc flags, line spacing */
  79. X    u_short l_count; /* total pargaphs & lines */
  80. X    u_short pnum, lnum; /* current position */
  81. X    struct TextFont *savefont;
  82. X    u_short *propwidth;
  83. X    struct textbody *body;
  84. X};
  85. X
  86. Xstruct HelpNode {
  87. X    struct  openwindows *ln_Succ;
  88. X    struct  openwindows *ln_Pred;
  89. X};
  90. X
  91. X#define ow_REFRESH 1
  92. X#define ow_ICONIZED 2
  93. X#define ow_SIZED 4
  94. X#define ow_PRINTWINDOW 8
  95. X#define ow_PRINTFILE 16
  96. X#define ow_PRINTING 32
  97. Xstruct openwindows {
  98. X    struct HelpNode node;
  99. X    struct Window *window;
  100. X    struct Gadget *scroll,*up,*down,*icon;
  101. X    struct doc *doc;
  102. X    /* Save window dimensions of the current window, to prevent */
  103. X    /* race conditions, and remember where hidden windows where */
  104. X    SHORT LeftEdge, TopEdge;
  105. X    SHORT Width, Height; /* Prevent race condition with user resizes */
  106. X    SHORT MinWidth, MinHeight;
  107. X    /*    */
  108. X    short  wide,high; /* character dimensions */
  109. X    /* Save window dimensions of the icon or full size window */
  110. X    short savewide, savehigh, saveleft, savetop;
  111. X    short saveminwidth, saveminheight;
  112. X    u_short flags;
  113. X};
  114. X
  115. SHAR_EOF
  116. echo "extracting image.c"
  117. sed 's/^X//' << \SHAR_EOF > image.c
  118. X/* HyperHelp -- Copyright 1989 Joe Porkka */
  119. X
  120. X/* image.c -- Contains the image data for the arrow gadgets.
  121. X          NOTE: The data part of this file *MUST* be forced
  122. X            into CHIP memory.
  123. X*/
  124. X
  125. Xtypedef unsigned short USHORT;
  126. X        /*       FEDCBA9876543210 */
  127. X
  128. X/*
  129. X   The DATA section of this file must be forced into CHIP memory by
  130. X   the compiler.
  131. X   I want the program to be compiled with 16bit register offset addressing
  132. X   for efficiency.
  133. X   This causes a link error, since this DATA section
  134. X   can not be combined with the rest of the DATA sections.
  135. X   This function allows me to compile the rest of the program with 16bit
  136. X   addressing.
  137. X*/
  138. Xstatic USHORT upimage[10]={
  139. X 0xc000,    /*       11.............. */
  140. X 0xffff,    /*       1111111111111111 */
  141. X 0xfcff,    /*       111111..11111111 */
  142. X 0xf03f,    /*       1111......111111 */
  143. X 0xe49f,    /*       111..1..1..11111 */
  144. X 0xcccf,    /*       11..11..11..1111 */
  145. X 0xfcff,    /*       111111..11111111 */
  146. X 0xfcff,    /*       111111..11111111 */
  147. X 0xffff,    /*       1111111111111111 */
  148. X 0xc000     /*       11.............. */
  149. X};
  150. Xstatic USHORT downimage[9]={
  151. X 0xffff,    /*       1111111111111111 */
  152. X 0xfcff,    /*       111111..11111111 */
  153. X 0xfcff,    /*       111111..11111111 */
  154. X 0xcccf,    /*       11..11..11..1111 */
  155. X 0xe49f,    /*       111..1..1..11111 */
  156. X 0xf03f,    /*       1111......111111 */
  157. X 0xfcff,    /*       111111..11111111 */
  158. X 0xffff,    /*       1111111111111111 */
  159. X 0xc000     /*       11.............. */
  160. X};
  161. X
  162. X/*  nk. ( repeat 1 ((11..) del del del del left left left left down)) */ */
  163. X
  164. XUSHORT iconimage[40]={
  165. X    0xcfff, 0xffc0,    /* 11.. 1111 1111 1111 1111 1111 11...... */
  166. X    0xcc00, 0x00c0,    /* 11.. 11.. .... .... .... .... 11...... */
  167. X    0xccff, 0xc0c0,    /* 11.. 11.. 1111 1111 11.. .... 11...... */
  168. X    0xccff, 0xc0c0,    /* 11.. 11.. 1111 1111 11.. .... 11...... */
  169. X    0xccff, 0xc0c0,    /* 11.. 11.. 1111 1111 11.. .... 11...... */
  170. X    0xccff, 0xc0c0,    /* 11.. 11.. 1111 1111 11.. .... 11...... */
  171. X    0xcc00, 0x00c0,    /* 11.. 11.. .... .... .... .... 11...... */
  172. X    0xcc00, 0x00c0,    /* 11.. 11.. .... .... .... .... 11...... */
  173. X    0xcc00, 0x00c0,    /* 11.. 11.. .... .... .... .... 11...... */
  174. X    0xcfff, 0xffc0,    /* 11.. 1111 1111 1111 1111 1111 11...... */
  175. X
  176. X    0x0000, 0x0000,    /* .... .... .... .... .... .... ........ */
  177. X    0x0000, 0x0f00,    /* .... .... .... .... .... 1111 ........ */
  178. X    0x00ff, 0xcf00,    /* .... .... 1111 1111 11.. 1111 ........ */
  179. X    0x00ff, 0xcf00,    /* .... .... 1111 1111 11.. 1111 ........ */
  180. X    0x00ff, 0xcf00,    /* .... .... 1111 1111 11.. 1111 ........ */
  181. X    0x00ff, 0xcf00,    /* .... .... 1111 1111 11.. 1111 ........ */
  182. X    0x0c00, 0x0f00,    /* .... .... .... .... .... 1111 ........ */
  183. X    0x0fff, 0xff00,    /* .... 1111 1111 1111 1111 1111 ........ */
  184. X    0x0fff, 0xff00,    /* .... 1111 1111 1111 1111 1111 ........ */
  185. X    0x0000, 0x0000     /* .... .... .... .... .... .... ........ */
  186. X};
  187. X
  188. Xvoid getimages(up, down, icon)
  189. X    USHORT **up, **down, **icon;
  190. X{
  191. X    *up=upimage;
  192. X    *down=downimage;
  193. X    *icon=iconimage;
  194. X}
  195. X
  196. X
  197. SHAR_EOF
  198. echo "extracting indev.c"
  199. sed 's/^X//' << \SHAR_EOF > indev.c
  200. X#include <exec/types.h>
  201. X#include <exec/ports.h>
  202. X/* #include <exec/memory.h> */
  203. X#include <exec/io.h>
  204. X#include <exec/tasks.h>
  205. X#include <exec/interrupts.h>
  206. X#include <devices/input.h>
  207. X#include <exec/devices.h>
  208. X#include <devices/inputevent.h>
  209. X
  210. XUBYTE recevent;
  211. XUWORD Code, Qual;
  212. X
  213. Xstatic struct MsgPort *inputDevPort;
  214. Xstatic struct IOStdReq *inputRequestBlock;
  215. Xstatic struct Interrupt handlerStuff;
  216. X
  217. Xextern struct MsgPort *CreatePort();
  218. Xextern struct IOStdReq *CreateStdIO();
  219. X
  220. Xextern HandlerInterface();
  221. Xextern unsigned int HotKeyCode, HotKeyQual;
  222. Xint mysig;
  223. X
  224. Xextern long stdout, debug;
  225. X
  226. Xint
  227. Xwaitforhotkey() {
  228. X    SHORT error;
  229. X    int signum=0, status;
  230. X
  231. X    inputDevPort=0;
  232. X    inputRequestBlock=0;
  233. X    recevent=0;
  234. X
  235. X    mysig= 1 << (signum=AllocSignal(-1));
  236. X    if (signum==0) goto fail;
  237. X
  238. X    inputDevPort = CreatePort(0,0);         /* for input device */
  239. X    if(inputDevPort == NULL) {              /* error during createport */
  240. X        goto fail;
  241. X    }
  242. X    inputRequestBlock = CreateStdIO(inputDevPort);
  243. X    if(inputRequestBlock == 0) {
  244. X        goto fail;
  245. X    }
  246. X
  247. X    handlerStuff.is_Data = 0;
  248. X    handlerStuff.is_Code = (VOID *)HandlerInterface;
  249. X    handlerStuff.is_Node.ln_Pri = 51;
  250. X    error = OpenDevice("input.device",0,inputRequestBlock,0);
  251. X    if(error) {
  252. X        DeleteStdIO(inputRequestBlock);
  253. X        inputRequestBlock=0;
  254. X        goto fail;
  255. X    }
  256. X
  257. X    inputRequestBlock->io_Command = IND_ADDHANDLER;
  258. X    inputRequestBlock->io_Data = (APTR)&handlerStuff;
  259. X
  260. X    DoIO(inputRequestBlock);
  261. X#ifdef DEBUG1
  262. X    dmsg(1,"Handler installed.\n");
  263. X#endif
  264. X
  265. X#ifdef DEBUG1
  266. X    dmsg(1,"HotKeyCode=%ld, Qual=%ld\n",HotKeyCode, HotKeyQual);
  267. X#endif
  268. X    for(;;)
  269. X    {
  270. X        recevent=0;
  271. X        do {
  272. X        Wait(-1);
  273. X        } while(recevent==0);
  274. X
  275. X#ifdef DEBUG1
  276. X        dmsg(1,".");
  277. X#endif
  278. X        /*
  279. X        if(Code == 95 && (Qual & 0x0009)==0x0009) {
  280. X        status=0;
  281. X        recevent=0;
  282. X        break;
  283. X        } else
  284. X        */
  285. X        if(Code == HotKeyCode && (Qual & HotKeyQual)==HotKeyQual) {
  286. X        status=1;
  287. X        recevent=0;
  288. X        break;
  289. X        }
  290. X    }
  291. X
  292. X    /* remove the handler from the chain */
  293. X    inputRequestBlock->io_Command = IND_REMHANDLER;
  294. X    inputRequestBlock->io_Data = (APTR)&handlerStuff;
  295. X    DoIO(inputRequestBlock);
  296. X    CloseDevice(inputRequestBlock);
  297. X    DeleteStdIO(inputRequestBlock);
  298. X    DeletePort(inputDevPort);
  299. X    if(signum) FreeSignal(signum);
  300. X    return status;
  301. X
  302. Xfail:
  303. X    if(inputRequestBlock) {
  304. X        CloseDevice(inputRequestBlock);
  305. X        DeleteStdIO(inputRequestBlock);
  306. X    }
  307. X    if(inputDevPort) DeletePort(inputDevPort);
  308. X    if(signum) FreeSignal(signum);
  309. X    return 0;
  310. X}
  311. SHAR_EOF
  312. echo "extracting index.c"
  313. sed 's/^X//' << \SHAR_EOF > index.c
  314. X/* HyperHype -- Copyright 1989 Joe Porkka */
  315. X
  316. X/* index.c -- look up a word in an index file */
  317. X
  318. X#include <exec/types.h>
  319. X#include <exec/memory.h>
  320. X#include <libraries/dos.h>
  321. X#include <libraries/dosextens.h>
  322. X#include "help.h"
  323. X#define DEBUG1
  324. X
  325. X
  326. X#define MAXWORDLEN 500
  327. X#define QUOTE_CHAR '"'
  328. X#define ESC_CHAR '\\'
  329. X#define GETCHAR  {\
  330. X    len--;\
  331. X    pos++;\
  332. X    if (len<=0) {\
  333. X    if ((len=Read(fh,pos=buffer,blocksize))<=0) return 0;\
  334. X    }\
  335. X}
  336. X
  337. X/* #define INDEXFILE "help:index" */
  338. X
  339. Xstatic u_char *buffer;
  340. Xstatic u_long blocksize;
  341. Xextern u_long oserr;
  342. Xextern int debug;
  343. X
  344. Xu_char *
  345. Xlookup(fh,word,wlen)
  346. X    u_long fh;
  347. X    u_char *word;
  348. X    int wlen;
  349. X{
  350. X    register u_char *pos=0, *wpos, *wend=word+wlen, a, b;
  351. X    int len=0;
  352. X#ifdef DEBUG1
  353. X    dmsg(1,"lookup(fh,'%s',%ld);\n",word,wlen);
  354. X#endif
  355. X    do {
  356. X    for(wpos=word;wpos<wend;wpos++) {
  357. X        GETCHAR;
  358. X        a=*pos; if(a==' ' || a=='\t' || a=='\n') break;
  359. X        b=*wpos;
  360. X#ifdef DEBUG1
  361. X        dmsg(1,"%lc%lc,",a,b);
  362. X#endif
  363. X        if(a!=b) {
  364. X        if(a>='a' && a<='z') a-=32;
  365. X        if(b>='a' && b<='z') b-=32;
  366. X        if(a != b ) break;
  367. X        }
  368. X    }
  369. X    if(wpos==wend) {
  370. X#ifdef DEBUG1
  371. X        dmsg(1,"\nGOTIT!\n");
  372. X#endif
  373. X        GETCHAR;
  374. X        return(pos);
  375. X    }
  376. X    while (*pos!='\n') GETCHAR;
  377. X#ifdef DEBUG1
  378. X    dmsg(1,"\n");
  379. X#endif
  380. X    } while(1);
  381. X    return(0);
  382. X}
  383. X
  384. Xvoid
  385. Xindex(filename,key)
  386. X    u_char *filename;
  387. X    struct key *key;
  388. X{
  389. X    int wlen;
  390. X    u_char *word=key->name;
  391. X    u_long fh=0, len;
  392. X    u_char *pos;
  393. X    int  usedlen;
  394. X
  395. X    for(wlen=0;key->name[wlen]!=' ' && key->name[wlen]!=0;wlen++);
  396. X    key->length=key->type=0;
  397. X    key->name=0;
  398. X
  399. X#ifdef DEBUG1
  400. X    dmsg(1,"\nINDEX.index() Looking up '");
  401. X#endif
  402. X    fh=openindexfile(filename);
  403. X    if(fh==0) {
  404. X#ifdef DEBUG5
  405. X    dmsg(5,"Error opening '%s' IoErr==%ld\n",filename,oserr);
  406. X#endif
  407. X    goto fail;
  408. X    }
  409. X    oserr=0;
  410. X    pos=lookup(fh,word,wlen);
  411. X    if(pos==0) {
  412. X#ifdef DEBUG1
  413. X    dmsg(1,"FAILED!\n");
  414. X#endif
  415. X    goto fail;
  416. X    }
  417. X    len= buffer+blocksize-pos;
  418. X#ifdef DEBUG1
  419. X    dmsg(1,"INDEX RETURNS:\n'");
  420. X#endif
  421. X
  422. X    while(*pos!='\t' && *pos!=' ') {
  423. X    pos++;
  424. X    if ( len == 0 ) {
  425. X        if ( ((len=Read(fh,pos=buffer,blocksize))==0)){
  426. X        oserr=IoErr();
  427. X#ifdef DEBUG5
  428. X        dmsg(5,"IOERR=%ld ",oserr);
  429. X#endif
  430. X        goto fail;
  431. X        }
  432. X    }
  433. X    len--;
  434. X    }
  435. X
  436. X    while (*pos==' ' ||*pos=='\t') {
  437. X    pos++;
  438. X    if ( len == 0 ) {
  439. X        if ( ((len=Read(fh,pos=buffer,blocksize))==0)){
  440. X        oserr=IoErr();
  441. X#ifdef DEBUG5
  442. X        dmsg(5,"IOERR=%ld ",oserr);
  443. X#endif
  444. X        goto fail;
  445. X        }
  446. X    }
  447. X    len--;
  448. X    }
  449. X    if( *pos=='x' || *pos=='X' )
  450. X    key->type=1;
  451. X    else if(*pos!='r' && *pos!='R') {
  452. X#ifdef DEBUG6
  453. X    dmsg(6,"Error in index file!!'%lc'\n",*pos);
  454. X#endif
  455. X    goto fail;
  456. X    }
  457. X
  458. X    do {
  459. X    pos++;
  460. X    if ( len == 0 ) {
  461. X        if ( ((len=Read(fh,pos=buffer,blocksize))==0)){
  462. X        oserr=IoErr();
  463. X#ifdef DEBUG5
  464. X        dmsg(5,"IOERR=%ld ",oserr);
  465. X#endif
  466. X        goto fail;
  467. X        }
  468. X    }
  469. X    len--;
  470. X    } while(*pos=='\t' || *pos==' ');
  471. X
  472. X    key->length=80;
  473. X    key->name=(u_char *)AllocMem(key->length,MEMF_CLEAR);
  474. X    if(key->name==0) goto fail;
  475. X    usedlen=0;
  476. X    while( 1 ) {
  477. X    key->name[usedlen++]=*pos;
  478. X
  479. X    if(*pos++=='\n') {
  480. X        key->name[--usedlen]=0;
  481. X        break;
  482. X    }
  483. X
  484. X    if(usedlen>=key->length) {
  485. X        u_char *t;
  486. X        t=(u_char *)AllocMem(key->length+80,MEMF_CLEAR);
  487. X        if(t==0) {
  488. X        goto fail;
  489. X        }
  490. X        CopyMem(key->name,t,key->length);
  491. X        FreeMem(key->name,key->length);
  492. X        key->name=t;
  493. X        key->length+=80;
  494. X    }
  495. X    if ( len == 0 ) {
  496. X        if ( ((len=Read(fh,pos=buffer,blocksize))==0)){
  497. X        oserr=IoErr();
  498. X#ifdef DEBUG"IOERR=%ld "
  499. X        dmsg("IOERR=%ld ",oserr);
  500. X#endif
  501. X        break;
  502. X        }
  503. X    }
  504. X    len--;
  505. X
  506. X    }
  507. X    if(fh) closeindexfile(fh);
  508. X    return;
  509. Xfail:
  510. X    if(key->name!=0 && key->length!=0) FreeMem(key->name,key->length);
  511. X    key->name=0;
  512. X    key->length=0;
  513. X    if(fh) closeindexfile(fh);
  514. X    return ;
  515. X}
  516. X
  517. Xu_long
  518. Xopenindexfile(name)
  519. X    u_char *name;
  520. X{
  521. X    struct InfoData *diskinfo=0;
  522. X    struct  Lock *lock=0,*Lock();        /* to get info about the disk */
  523. X    u_long fh=0;
  524. X
  525. X    buffer=0;
  526. X    blocksize=0;
  527. X
  528. X    if( (diskinfo=(struct InfoData *)AllocMem(sizeof(struct InfoData),0))==0) goto fail;
  529. X
  530. X    if( (lock=Lock(name,1005))==0) {
  531. X    oserr=IoErr();
  532. X    goto fail;
  533. X    }
  534. X    if( Info(lock,diskinfo)==0) {
  535. X    oserr=IoErr();
  536. X    goto fail;
  537. X    }
  538. X    blocksize=diskinfo->id_BytesPerBlock;
  539. X    if (diskinfo) FreeMem((u_char *)diskinfo,sizeof(struct InfoData));
  540. X    diskinfo=0;
  541. X    buffer=(u_char *)AllocMem(blocksize,0);
  542. X    if(buffer==0) {
  543. X    oserr=103;
  544. X    goto fail;
  545. X    }
  546. X    if( (fh=Open(name,1005))==0){
  547. X    oserr=IoErr();
  548. X    goto fail;
  549. X    }
  550. X    UnLock(lock);
  551. X    oserr=0;
  552. X    return(fh);
  553. X
  554. Xfail:
  555. X    if (lock)     UnLock(lock);
  556. X    if (fh) Close(fh);
  557. X    if (diskinfo) FreeMem((u_char *)diskinfo,sizeof(struct InfoData));
  558. X    if (blocksize && buffer) FreeMem(buffer,blocksize);
  559. X    blocksize=0;
  560. X    buffer=0;
  561. X    return(0);
  562. X}
  563. X
  564. Xvoid
  565. Xcloseindexfile(fh)
  566. X    u_long fh;
  567. X{
  568. X    if (fh==0) return;
  569. X    if (blocksize && buffer) FreeMem(buffer,blocksize);
  570. X    blocksize=0;
  571. X    buffer=0;
  572. X    Close(fh);
  573. X    fh=0;
  574. X}
  575. X
  576. X
  577. SHAR_EOF
  578. echo "extracting kludge.h"
  579. sed 's/^X//' << \SHAR_EOF > kludge.h
  580. X/* The following ugliness if brought to you by a BUG in LATTICE 3.10 */
  581. X    /* printitout(); */
  582. X    if(printing) {
  583. X    dmsg(1,"Cancel print job! printing=%ld\n",printing);
  584. X    printing=0;
  585. X    if(printow) {
  586. X        closewindow(printow);
  587. X        printow=0;
  588. X        dmsg(1,"About to dnit print\n");
  589. X        printdnit();
  590. X    }
  591. X    dmsg(1,"About to free printbuffer...");
  592. X    if(printbuf && printbuflen) FreeMem(printbuf,printbuflen);
  593. X    printbuf=0;
  594. X    printbuflen=0;
  595. X    dmsg(1,"Freed!\n");
  596. X    }
  597. X
  598. SHAR_EOF
  599. echo "extracting link"
  600. sed 's/^X//' << \SHAR_EOF > link
  601. Xfrom c.o+debug.o+print.o+tokens.o+menu.o+indev.o+grandcentral.o+cxm33.o+fileinit.o+getfile.o+index.o+findwordinline.o+format.o+move.o+cxd33.o+image.o+displayline.o+windows.o+main.o+gen.o+oserr.o+getenv.o+gc2.o
  602. Xto help
  603. Xlib lib:amiga.lib
  604. Xsmalldata
  605. Xnodebug
  606. X
  607. SHAR_EOF
  608. echo "extracting main.c"
  609. sed 's/^X//' << \SHAR_EOF > main.c
  610. X/* HyperHelp -- Copyright 1989 Joe Porkka */
  611. X
  612. X/* main.c -- Handles startup and shut down of HyperHelp */
  613. X
  614. X#include <intuition/intuition.h>
  615. X#include <exec/memory.h>
  616. X#include <graphics/text.h>
  617. X#include "help.h"
  618. X#include "helptext.h"
  619. X
  620. Xextern long stdin, stdout,oserr, outwindow;
  621. Xextern short windowcount, menucount;
  622. Xextern struct Screen *screen;
  623. Xextern struct List windowhead;
  624. Xextern struct TextAttr font;
  625. X
  626. Xlong IntuitionBase=0, GfxBase=0, DiskfontBase=0;
  627. Xstruct MsgPort *mp, *CreatePort(), *FindPort();
  628. Xlong debug;
  629. X
  630. X/* Environment externals */
  631. X
  632. Xextern int ScreenType;
  633. Xextern char *ENVRootFile, *ENVIndexFile;
  634. Xextern int ENVAskFirst;
  635. Xextern struct TextAttr *ENVFont;
  636. X
  637. Xchar *RootFile, *IndexFile;
  638. X
  639. Xvoid
  640. Xmain(av,ac)
  641. X    int av;
  642. X    char *ac;
  643. X{
  644. X    char *string=0;
  645. X    int test, quiet;
  646. X    struct openwindows *ow;
  647. X
  648. X    debug=0; test=0; quiet=0;
  649. X    ENVRootFile=ENVIndexFile=0;
  650. X    RootFile="help:toplevel";
  651. X    IndexFile="help:index";
  652. X    while (av>0) {
  653. X    if(string==0) string=arg(&av, &ac);
  654. X    dmsg(1,"string='%s' av=%ld ac='%s'.\n",string,av,ac);
  655. X    if(strnicmp("debug",string,5)==0) {
  656. X        debug=1;
  657. X        string=arg(&av, &ac);
  658. X        if(*string> '0' && *string <='9') {
  659. X        debug = *string-'0';
  660. X        string=0;
  661. X        }
  662. X    } else if(strnicmp("quiet",string,5)==0) {
  663. X        quiet=1;
  664. X        string=0;
  665. X    }
  666. X    }
  667. X    if(startup()==0) goto fail;
  668. X#ifdef DEBUG9
  669. X    dmsg(9,"Debug level=%ld., string='%s'\n",debug,string);
  670. X#endif
  671. X
  672. X    if(ENVRootFile) RootFile=ENVRootFile;
  673. X    if(ENVIndexFile) IndexFile=ENVIndexFile;
  674. X    if(quiet) {
  675. X    dmsg(1,"Waiting for hotkey!\n");
  676. X    if(!waitforhotkey()) {
  677. X        die("canel quiet mode!");
  678. X        goto fail;
  679. X    }
  680. X    }
  681. X
  682. X    do    {
  683. X    /*
  684. X    if(windowcount==0) {
  685. X        ow=getfile(RootFile);
  686. X        if(ow==0) {
  687. X        die("Could not open initial file.");
  688. X        goto fail;
  689. X        }
  690. X        refresh(ow);
  691. X    }
  692. X    */
  693. X    test=grandcentral();
  694. X    if(test) test=waitforhotkey();
  695. X    } while(test);
  696. X
  697. X    die("All done!");
  698. Xfail:
  699. X    stdout=0;
  700. X    /* return; */
  701. X}
  702. X
  703. Xint
  704. Xstartup() {
  705. X
  706. X    stdout=0;
  707. X    stdin=0;
  708. X    mp=0; windowcount=0; menucount=0;
  709. X    screen=0;
  710. X    if(fileinit()==0) {
  711. X    die("Could not start IO stuff.");
  712. X    return(0);
  713. X    }
  714. X    meminit();
  715. X    /* Open V1.2 Libraries */
  716. X    if ( (IntuitionBase= OpenLibrary("intuition.library",33)) == 0 ||
  717. X     (GfxBase      = OpenLibrary("graphics.library",33))  == 0) {
  718. X     die("Could not open system libraries.");
  719. X     return(0);
  720. X    }
  721. X    /* Don't get installed twice! */
  722. X    Forbid();
  723. X    mp=FindPort("HyperHelp");
  724. X    Permit();
  725. X    if(mp) {
  726. X    mp=0;
  727. X    die("HyperHelp already installed!");
  728. X    return(0);
  729. X    }
  730. X    if( (mp=CreatePort("HyperHelp",0))==0) {
  731. X    die("Could not Allocate a Port.");
  732. X    return(0);
  733. X    }
  734. X
  735. X    getenv(); /* This MUST be before windowinit() !!! */
  736. X
  737. X    if(windowinit()==0) {
  738. X    die("Could not start windows stuff.");
  739. X    return(0);
  740. X    }
  741. X
  742. X    return(-1);
  743. X}
  744. X
  745. Xvoid
  746. Xshutdown() {
  747. X    /* struct openwindows *ow; */
  748. X    struct IntuiMessage *im,*GetMsg();
  749. X
  750. X    if(IntuitionBase) {
  751. X    closeallwindows();
  752. X    if(mp) {
  753. X        while(im=GetMsg(mp)) {
  754. X        ReplyMsg(im);
  755. X        }
  756. X        DeletePort(mp);
  757. X        mp=0;
  758. X    }
  759. X    if(screen!=0) {
  760. X#ifdef DEBUG9
  761. X        dmsg(9,"Main had to close the screen!!\n");
  762. X#endif
  763. X        CloseScreen(screen);
  764. X        screen=0;
  765. X    }
  766. X    CloseLibrary(IntuitionBase);
  767. X    IntuitionBase=0;
  768. X    }
  769. X    if(GfxBase) {
  770. X    CloseLibrary(GfxBase);
  771. X    GfxBase=0;
  772. X    }
  773. X    if(DiskfontBase) {
  774. X    CloseLibrary(DiskfontBase);
  775. X    DiskfontBase=0;
  776. X    }
  777. X    if(ENVRootFile) FreeMem(ENVRootFile, strlen(ENVRootFile)+1);
  778. X    if(ENVIndexFile) FreeMem(ENVIndexFile, strlen(ENVIndexFile)+1);
  779. X    if(ENVFont) {
  780. X    if(ENVFont->ta_Name) FreeMem(ENVFont->ta_Name, strlen(ENVFont->ta_Name)+1);
  781. X    FreeMem(ENVFont,sizeof(struct TextAttr));
  782. X    ENVFont=0;
  783. X    }
  784. X    ENVRootFile=ENVIndexFile=0;
  785. X    membye();
  786. X    if(outwindow) Close(outwindow);
  787. X    outwindow=0;
  788. X    stdout=0;
  789. X}
  790. X
  791. Xvoid
  792. Xdie(string)
  793. X    char *string;
  794. X{
  795. X    if(string)
  796. X#ifdef DEBUG5
  797. X    dmsg(5,"HELP: %s\n",string);
  798. X#endif
  799. X    shutdown();
  800. X}
  801. X
  802. X/* These functions shuld be in grandcentral.c
  803. X   However, lc1 runs out of mem if they are there
  804. X*/
  805. Xvoid
  806. Xclosewindow(tmpow)
  807. X    struct openwindows *tmpow;
  808. X{
  809. X#ifdef DEBUG1
  810. X    dmsg(1,"Going to closewindowsafely...");
  811. X#endif
  812. X    closewindowsafely(tmpow);
  813. X#ifdef DEBUG1
  814. X    dmsg(1,"closed!\n");
  815. X#endif
  816. X    tmpow->window=0;
  817. X    Remove(tmpow);
  818. X#ifdef DEBUG1
  819. X    dmsg(1,"Freeingfile...");
  820. X#endif
  821. X    freefile(tmpow->doc);
  822. X#ifdef DEBUG1
  823. X    dmsg(1,"Freed!\n");
  824. X#endif
  825. X    FreeMem(tmpow,sizeof(struct openwindows) );
  826. X#ifdef DEBUG1
  827. X    dmsg(1,"tompow freed!\n");
  828. X#endif
  829. X}
  830. X
  831. X/* From print.c */
  832. Xextern struct IOStdReq *printreq;
  833. Xextern int printing, printbuflen;
  834. Xextern u_char *printbuf;
  835. Xextern struct openwindows *printow;
  836. Xprintitout()
  837. X{
  838. X    struct openwindows *ow;
  839. X    struct doc *doc;
  840. X    struct textbody *body;
  841. X#ifdef DEBUG1
  842. X    dmsg(1,"windowcount=%ld\n",windowcount);
  843. X#endif
  844. X    for(ow=(struct openwindows*)windowhead.lh_Head ; ow->node.ln_Succ; ow=ow->node.ln_Succ) {
  845. X#ifdef DEBUG1
  846. X    dmsg(1,"\nOW->HelpNode=%lx, window=%ld, scroll=%ld, doc=%ld flags=0x%lx\n",
  847. X        &ow->node, ow->window, ow->scroll, ow->doc, ow->flags);
  848. X#endif
  849. X    doc=ow->doc;
  850. X    if(doc) {
  851. X#ifdef DEBUG1
  852. X        dmsg(1,"DOC labc=%ld, labs=%ld pc=%ld parag=%ld, lcount=%ld, pnum=%ld, lnum=%ld\n",
  853. X        doc->lab_count, doc->labs, doc->p_count, doc->p, doc->l_count, doc->pnum, doc->lnum);
  854. X#endif
  855. X#ifdef DEBUG1
  856. X        dmsg(1,"\tsavefont=%ld body=%ld\n",doc->savefont, doc->body);
  857. X#endif
  858. X        body=doc->body;
  859. X        if(body) {
  860. X#ifdef DEBUG1
  861. X        dmsg(1,"BODY text=%ld, filename='%s', len=%ld, usecount=%ld\n",
  862. X        body->text, body->filename, body->length, body->usecount);
  863. X#endif
  864. X        }
  865. X    }
  866. X    }
  867. X    if(stdout) {
  868. X#ifdef DEBUG1
  869. X    dmsg(1,"PRESS ENTER!");
  870. X#endif
  871. X    Read(stdout,"buffer",1);
  872. X    }
  873. X}
  874. X
  875. Xcloseallwindows()
  876. X{
  877. X    struct openwindows *ow;
  878. X
  879. X    while(ow=(struct openwindows *)RemHead(&windowhead)) {
  880. X    if(ow->flags & ow_PRINTING) {
  881. X#ifdef DEBUG1
  882. X        dmsg(1,"main:Closeing off a printing file!\n");
  883. X#endif
  884. X        if(printreq) {
  885. X        int error=AbortIO(printreq);
  886. X
  887. X        if(error) {
  888. X#ifdef DEBUG99
  889. X            dmsg(99,"AbortIO(printreq)=%ld. BADTHING\n",error);
  890. X#endif
  891. X        }
  892. X        WaitIO(printreq);
  893. X        printing=0;
  894. X        }
  895. X#include "kludge.h"
  896. X        /* cancelprintjob(); */
  897. X#ifdef DEBUG10
  898. X        dmsg(10,"MAIN BACK FROM CANCEL!\n");
  899. X#endif
  900. X    } else {
  901. X        closewindowsafely(ow);
  902. X    }
  903. X    freefile(ow->doc);
  904. X    FreeMem(ow,sizeof(struct openwindows));
  905. X    }
  906. X}
  907. X
  908. X/* Put up an AutoRequester to verify an Execute before we do it */
  909. Xint
  910. Xaskforexec(win,exectext)
  911. X    struct Window *win;
  912. X    UBYTE  *exectext;
  913. X{
  914. X    static struct TextAttr font = {
  915. X    "topaz.font",9,0,0
  916. X    } ;
  917. X    /* IntuiTexts for the Body + OK + CANCEL buttons. Static to avoid the stack */
  918. X    static struct IntuiText body3={
  919. X    0,1,
  920. X    JAM2,6,19,&font,
  921. X    (UBYTE *)"Do you wish to allow it?",
  922. X    0
  923. X    };
  924. X    static struct IntuiText body2={
  925. X    0,1,
  926. X    JAM2,6,11,&font,
  927. X    0,
  928. X    &body3
  929. X    };
  930. X    static struct IntuiText body1={
  931. X    0,1,
  932. X    JAM2,6,3,&font,
  933. X    (UBYTE *)"That references attempts to make this execute",
  934. X    &body2
  935. X    };
  936. X    static struct IntuiText yesbutton={
  937. X    0,1,
  938. X    JAM2,6,4,&font,
  939. X    (UBYTE *)"Yes",
  940. X    0
  941. X    };
  942. X    static struct IntuiText nobutton={
  943. X    0,1,
  944. X    JAM2,6,4,&font,
  945. X    (UBYTE *)"No!",
  946. X    0
  947. X    };
  948. X
  949. X    int textlen, width,test;
  950. X    char tmp[64];
  951. X    if(!ENVAskFirst) return 1;
  952. X    textlen=strlen(exectext);
  953. X    if(textlen>60) textlen=60;
  954. X    strncpy(tmp,exectext,60);
  955. X    tmp[60]=0;
  956. X    width=strlen(body1.IText);
  957. X    if(width<textlen) width=textlen;
  958. X    body2.IText=tmp;
  959. X
  960. X    dmsg(1,"****\nAutorequest Width=%ld.\n",width);
  961. X
  962. X    test=AutoRequest(win,&body1,&yesbutton, &nobutton,0,0,width*10+40,63);
  963. X    return test;
  964. X}
  965. X
  966. X/* About()
  967. X    HyperHelp  Version 1.0
  968. X    Written by Joe Porkka -- porkka@frith.egr.msu.edu
  969. X    Copyight 1989 Joe Porkka. All rights reserved.
  970. X    (517) 337-9472
  971. X*/
  972. Xabout(win)
  973. X    struct Window *win;
  974. X{
  975. X    static struct TextAttr font = {
  976. X    "topaz.font",8,0,0
  977. X    };
  978. X    /* IntuiTexts for the Body + OK buttons. Static to avoid the stack */
  979. X    static struct IntuiText body4={
  980. X    0,1,
  981. X    JAM2,6,30,&font,
  982. X    (UBYTE *)"(517) 337-9472",
  983. X    0
  984. X    };
  985. X    static struct IntuiText body3={
  986. X    0,1,
  987. X    JAM2,6,21,&font,
  988. X    (UBYTE *)"Copyright 1989 Joe Porkka. All right reserved.",
  989. X    &body4
  990. X    };
  991. X    static struct IntuiText body2={
  992. X    0,1,
  993. X    JAM2,6,12,&font,
  994. X    (UBYTE*)"Written by Joe Porkka -- porkka@frith.egr.msu.edu",
  995. X    &body3
  996. X    };
  997. X    static struct IntuiText body1={
  998. X    0,1,
  999. X    JAM2,6,3,&font,
  1000. X    (UBYTE *)"HyperHelp Version 1.0",
  1001. X    &body2
  1002. X    };
  1003. X    static struct IntuiText yesbutton={
  1004. X    0,1,
  1005. X    JAM2,6,4,&font,
  1006. X    (UBYTE *)"OK!",
  1007. X    0
  1008. X    };
  1009. X
  1010. X    AutoRequest(win,&body1,&yesbutton, &yesbutton,0,0,strlen(body2.IText)*8+40,71);
  1011. X}
  1012. X
  1013. X
  1014. SHAR_EOF
  1015. echo "extracting menu.c"
  1016. sed 's/^X//' << \SHAR_EOF > menu.c
  1017. X/* HyperHelp -- Copyright 1989 Joe Porkka */
  1018. X
  1019. X/* menu.c -- Sets up and removes window menus.
  1020. X
  1021. X*/
  1022. X
  1023. X#include <intuition/intuition.h>
  1024. X#include <graphics/text.h>
  1025. X#include "help.h"
  1026. X#include "helptext.h"
  1027. X
  1028. Xextern long IntuitionBase, GfxBase, DiskfontBase;
  1029. Xextern int debug;
  1030. X
  1031. Xstatic struct Menu ControlMenu, PrintMenu;
  1032. Xstatic struct MenuItem CFile, COpen, CClose, CHide, CGo, CAbout;
  1033. Xstatic struct IntuiText TCFile, TCOpen, TCClose, TCHide, TCGo, TCAbout;
  1034. Xstatic struct MenuItem PWindow, PFile, PCancel;
  1035. Xstatic struct IntuiText TPWindow, TPFile, TPCancel;
  1036. X
  1037. Xstatic int titleh, titlew; /* Text dimensions */
  1038. X/* BAD thing: always use topaz 9 */
  1039. X/* Also used in main for the AutoRequest */
  1040. Xstruct TextAttr font={
  1041. X    "topaz.font",
  1042. X    9,
  1043. X    0,
  1044. X    0
  1045. X};
  1046. X
  1047. Xshort    menucount;
  1048. X
  1049. Xvoid
  1050. Xmakemenu(win)
  1051. X    struct Window *win;
  1052. X{
  1053. X#ifdef DEBUG1
  1054. X    dmsg(1,"MAKEMENU!\n");
  1055. X#endif
  1056. X    if(win==0) return;
  1057. X    if(!menucount) initmenus(win);
  1058. X    menucount++;
  1059. X#ifdef DEBUG1
  1060. X    dmsg(1,"About to set menu.\n");
  1061. X#endif
  1062. X    SetMenuStrip(win,&ControlMenu);
  1063. X#ifdef DEBUG1
  1064. X    dmsg(1,"Menu set window->MenuStrip=%ld\n",win->MenuStrip);
  1065. X#endif
  1066. X#ifdef DEBUG1
  1067. X    dmsg(1,"window->Flags=%08lx, IDCMP==%08lx.\n",win->Flags,win->IDCMPFlags);
  1068. X#endif
  1069. X}
  1070. X
  1071. Xvoid
  1072. Xremovemenu(win)
  1073. X    struct Window *win;
  1074. X{
  1075. X    if(menucount==0) {
  1076. X#ifdef DEBUG9
  1077. X    dmsg(9,"Attempt removemenu when menucount==0!\n");
  1078. X#endif
  1079. X    }
  1080. X    if(win->MenuStrip==0) {
  1081. X#ifdef DEBUG9
  1082. X    dmsg(9,"Attempt to removemenu without a menu!!\n");
  1083. X#endif
  1084. X    } else {
  1085. X    menucount--;
  1086. X    ClearMenuStrip(win);
  1087. X    }
  1088. X}
  1089. X
  1090. Xvoid
  1091. Xinitmenus(win)
  1092. X    struct Window *win;
  1093. X{
  1094. X    int left, width;
  1095. X
  1096. X#ifdef DEBUG1
  1097. X    dmsg(1,"Initializing menu structs.\n");
  1098. X#endif
  1099. X    titleh = win->WScreen->RastPort.TxHeight;
  1100. X    titlew = win->WScreen->RastPort.TxWidth;
  1101. X
  1102. X    left=titlew;
  1103. X    width=0;
  1104. X
  1105. X    domenu(&ControlMenu,"Control", &left);
  1106. X    domenu(&PrintMenu,"Print", &left);
  1107. X    ControlMenu.NextMenu = &PrintMenu;
  1108. X    PrintMenu.NextMenu=0;
  1109. X
  1110. X    domenuitem(&ControlMenu,&CFile, &TCFile,"Open A File",(BYTE)0, &width);
  1111. X    CFile.Flags &= ~ITEMENABLED;
  1112. X    domenuitem(&ControlMenu,&COpen, &TCOpen,"Open Root File",(BYTE)'O', &width);
  1113. X    domenuitem(&ControlMenu,&CClose, &TCClose,"Close All Windows",(BYTE)'C', &width);
  1114. X    domenuitem(&ControlMenu,&CHide, &TCHide, "Hide Windows",(BYTE)'H', &width);
  1115. X    domenuitem(&ControlMenu,&CGo, &TCGo, "Go Away",(BYTE)'G', &width);
  1116. X    domenuitem(&ControlMenu,&CAbout, &TCAbout, "About",(BYTE)'A', &width);
  1117. X
  1118. X    width=0;
  1119. X    domenuitem(&PrintMenu, &PWindow, &TPWindow, "Window Contents",(BYTE)'W', &width);
  1120. X    domenuitem(&PrintMenu, &PFile, &TPFile, "Entire File",(BYTE)'F', &width);
  1121. X    domenuitem(&PrintMenu, &PCancel, &TPCancel, "Cancel All Prints",(BYTE)'X', &width);
  1122. X}
  1123. X
  1124. Xvoid
  1125. Xdomenu(menu,text,left)
  1126. X    struct Menu *menu;
  1127. X    BYTE *text;
  1128. X    int *left;
  1129. X{
  1130. X    menu->LeftEdge = *left;
  1131. X    menu->TopEdge=0;
  1132. X    menu->Width = (strlen(text)+2)*titlew;
  1133. X    menu->Height=titleh;
  1134. X    menu->Flags =  MENUENABLED;
  1135. X    menu->MenuName=text;
  1136. X    menu->FirstItem=0;
  1137. X    *left +=menu->Width;
  1138. X}
  1139. X
  1140. Xvoid
  1141. Xdomenuitem(menu,item,fill,text,c, width)
  1142. X    struct Menu *menu;
  1143. X    struct MenuItem *item;
  1144. X    struct IntuiText *fill;
  1145. X    BYTE *text, c;
  1146. X    int *width;
  1147. X{
  1148. X    struct MenuItem *this;
  1149. X    int  count, thiswidth;
  1150. X
  1151. X    thiswidth = (strlen(text)+2)*10+COMMWIDTH;
  1152. X    this=menu->FirstItem;
  1153. X    if(this==0) {
  1154. X    count=0;
  1155. X    menu->FirstItem=item;
  1156. X    } else {
  1157. X    count=1;
  1158. X    while (this->NextItem) {
  1159. X        if(this->Width < thiswidth)
  1160. X        this->Width=thiswidth;
  1161. X        else
  1162. X        thiswidth=this->Width;
  1163. X        this=this->NextItem;
  1164. X        count++;
  1165. X    }
  1166. X    this->NextItem=item;
  1167. X    if(this->Width < thiswidth)
  1168. X        this->Width=thiswidth;
  1169. X    else
  1170. X        thiswidth=this->Width;
  1171. X    }
  1172. X    *width=thiswidth;
  1173. X    item->NextItem=0;
  1174. X    item->LeftEdge=0;
  1175. X    item->TopEdge=count*11; /* 9+2 */
  1176. X    item->Width = thiswidth;
  1177. X    item->Height = 11;
  1178. X    item->Flags = ITEMTEXT | (c ? COMMSEQ : 0) | ITEMENABLED | HIGHCOMP;
  1179. X    item->MutualExclude=0;
  1180. X    item->ItemFill=(APTR)fill;
  1181. X    item->Command=c;
  1182. X    item->SubItem=0;
  1183. X
  1184. X    fill->FrontPen=0; fill->BackPen=1;
  1185. X    fill->DrawMode = JAM2;
  1186. X    fill->LeftEdge=0;
  1187. X    fill->TopEdge=1;
  1188. X    fill->ITextFont=&font;
  1189. X    fill->IText=text;
  1190. X    fill->NextText=0;
  1191. X}
  1192. X
  1193. SHAR_EOF
  1194. echo "extracting move.c"
  1195. sed 's/^X//' << \SHAR_EOF > move.c
  1196. X/* HyperHelp -- Copyright 1989 Joe Porkka */
  1197. X
  1198. X/* move.c -- Controls movement thru a file + refresh of the windows */
  1199. X
  1200. X#include <intuition/intuition.h>
  1201. X#include "help.h"
  1202. X#include "helptext.h"
  1203. X
  1204. Xextern int PenColor, PaperColor;
  1205. Xextern int debug;
  1206. X
  1207. X
  1208. Xrectfill(rp,x1,y1,x2,y2,name,ow)
  1209. X    struct RastPort *rp;
  1210. X    long x1,y1,x2,y2;
  1211. X    u_char *name;
  1212. X    struct openwindows *ow;
  1213. X{
  1214. X    if(y1==y2) return;
  1215. X    if( x1 >= x2 || y1 >= y2) {
  1216. X#ifdef DEBUG9
  1217. X    dmsg(9,"****ERROR move.c: %s() BorderLeft >= Width-BorderRight\n",name);
  1218. X#endif
  1219. X#ifdef DEBUG9
  1220. X    dmsg(9,"****      x1=%ld, y1=%ld, x2=%ld, y2=%ld.\n",x1,y1,x2,y2);
  1221. X#endif
  1222. X#ifdef DEBUG9
  1223. X    dmsg(9,"          WindowDims=(%ld,%ld) BLeft=%ld, BRight=%ld\n",
  1224. X        ow->Width,
  1225. X        ow->Height,
  1226. X        ow->window->BorderLeft,
  1227. X        ow->window->BorderRight
  1228. X    );
  1229. X#endif
  1230. X    } else {
  1231. X    RectFill(rp,x1,y1,x2,y2);
  1232. X    }
  1233. X}
  1234. X#define RectFill rectfill
  1235. Xcleardisplay(ow)
  1236. X    struct openwindows *ow;
  1237. X{
  1238. X    struct RastPort *rp=ow->window->RPort;
  1239. X    SetAPen(rp,0);
  1240. X    RectFill(rp,
  1241. X    ow->window->BorderLeft,
  1242. X    ow->window->BorderTop,
  1243. X    ow->Width - ow->window->BorderRight,
  1244. X    ow->window->BorderTop + ow->high*rp->TxHeight,
  1245. X    "cleardisplay",
  1246. X    ow
  1247. X    );
  1248. X}
  1249. Xvoid
  1250. Xmoveto(ow,line)
  1251. X    struct openwindows *ow;
  1252. X    int line;
  1253. X{
  1254. X    int pos=currentlinenum(ow->doc);
  1255. X    if(pos-line==0) return;
  1256. X    move(ow,line-pos);
  1257. X}
  1258. X
  1259. Xvoid
  1260. Xmove(ow,dir)
  1261. X    int dir;
  1262. X    struct openwindows *ow;
  1263. X{
  1264. X    int count;
  1265. X    struct RastPort *rp=ow->window->RPort;
  1266. X    u_short pnum=ow->doc->pnum, lastp;
  1267. X    u_short lnum=ow->doc->lnum, lastl;
  1268. X    struct paragraph *p;
  1269. X
  1270. X    if(dir>0) {      /* MOVE DOWN */
  1271. X    if(dir>=ow->high) {
  1272. X        lastp=pnum;
  1273. X        lastl=lnum;
  1274. X        count=0;
  1275. X        p = &ow->doc->p[pnum];
  1276. X        while( count < ow->high) {
  1277. X        lastl++;
  1278. X        if(lastl >= p->count) {
  1279. X            lastl=0;
  1280. X            lastp++;
  1281. X            if(lastp >= ow->doc->p_count) {
  1282. X            count=0;
  1283. X            break;
  1284. X            } else {
  1285. X            p = &ow->doc->p[lastp];
  1286. X            }
  1287. X        }
  1288. X        count++;
  1289. X        }
  1290. X
  1291. X        while(dir>0 && count>0 ) {
  1292. X        dir--;
  1293. X        lastl++;
  1294. X        if(lastl >= ow->doc->p[lastp].count) {
  1295. X            lastl=0;
  1296. X            lastp++;
  1297. X            if(lastp >= ow->doc->p_count) {
  1298. X            count=0;
  1299. X            }
  1300. X        }
  1301. X        lnum++;
  1302. X        if(lnum >= ow->doc->p[pnum].count) {
  1303. X            lnum=0;
  1304. X            pnum++;
  1305. X            if(pnum >= ow->doc->p_count) {
  1306. X            count=0;
  1307. X            }
  1308. X        }
  1309. X        }
  1310. X        ow->doc->pnum=pnum;
  1311. X        ow->doc->lnum=lnum;
  1312. X        cleardisplay(ow);
  1313. X    } else {
  1314. X        while(dir>0) {
  1315. X        dir--;
  1316. X        lastp=pnum;
  1317. X        lastl=lnum;
  1318. X        count=0;
  1319. X        p = &ow->doc->p[pnum];
  1320. X        while( count < ow->high) {
  1321. X            lastl++;
  1322. X            if(lastl >= p->count) {
  1323. X            lastl=0;
  1324. X            lastp++;
  1325. X            if(lastp >= ow->doc->p_count) {
  1326. X                count=0;
  1327. X                break;
  1328. X            } else {
  1329. X                p = &ow->doc->p[lastp];
  1330. X            }
  1331. X            }
  1332. X            count++;
  1333. X        }
  1334. X        if(count) {
  1335. X            ScrollRaster(rp,0,rp->TxHeight,
  1336. X            ow->window->BorderLeft,
  1337. X            ow->window->BorderTop,
  1338. X            ow->Width - ow->window->BorderRight,
  1339. X            ow->window->BorderTop + ow->high*rp->TxHeight-1
  1340. X            );
  1341. X            lnum++;
  1342. X            if(lnum >= ow->doc->p[pnum].count) {
  1343. X            lnum=0;
  1344. X            pnum++;
  1345. X            if(pnum >= ow->doc->p_count) {
  1346. X                count=0;
  1347. X            }
  1348. X            }
  1349. X            if(count==0) {
  1350. X#ifdef DEBUG9
  1351. X            dmsg(9,"** BUG!! ** count==0 after count>0\n");
  1352. X#endif
  1353. X            break;
  1354. X            } else {
  1355. X            ow->doc->pnum=pnum;
  1356. X            ow->doc->lnum=lnum;
  1357. X            }
  1358. X
  1359. X            rp->cp_x= ow->window->BorderLeft;
  1360. X            rp->cp_y=rp->TxBaseline + (ow->high-1)*rp->TxHeight + ow->window->BorderTop;
  1361. X            displayline(rp,&ow->doc->p[lastp],lastl,ow,0,0);
  1362. X            /*
  1363. X            SetAPen(rp,PaperColor);
  1364. X            RectFill(rp,
  1365. X            rp->cp_x,
  1366. X            rp->cp_y-rp->TxBaseline,
  1367. X            ow->Width - ow->window->BorderRight,
  1368. X            rp->cp_y - rp->TxBaseline + rp->TxHeight,
  1369. X            "move",
  1370. X            ow
  1371. X            );
  1372. X            SetAPen(rp,PenColor);
  1373. X            */
  1374. X        } else dir=0;
  1375. X        }
  1376. X    }
  1377. X    } else if ( pnum > 0 || lnum > 0 ) {
  1378. X    if( -dir >= ow->high) {
  1379. X        while(dir<0 && (pnum>0 || lnum>0) ) {
  1380. X        dir++;
  1381. X        if(lnum==0 ) {
  1382. X            pnum--;
  1383. X            lnum = ow->doc->p[pnum].count ;
  1384. X        }
  1385. X        lnum--;
  1386. X        }
  1387. X        ow->doc->pnum=pnum;
  1388. X        ow->doc->lnum=lnum;
  1389. X        cleardisplay(ow);
  1390. X    } else {
  1391. X        while(dir<0 && (pnum>0 || lnum>0) ) {
  1392. X        dir++;
  1393. X        ScrollRaster(rp,0, -rp->TxHeight ,
  1394. X            ow->window->BorderLeft,
  1395. X            ow->window->BorderTop,
  1396. X            ow->Width - ow->window->BorderRight,
  1397. X            ow->window->BorderTop + ow->high*rp->TxHeight -1
  1398. X        );
  1399. X        if(lnum==0 ) {
  1400. X            pnum--;
  1401. X            lnum = ow->doc->p[pnum].count ;
  1402. X        }
  1403. X        lnum--;
  1404. X
  1405. X        rp->cp_x= ow->window->BorderLeft;
  1406. X        rp->cp_y= rp->TxBaseline +  ow->window->BorderTop;
  1407. X        displayline(rp,&ow->doc->p[pnum],lnum,ow,0,0);
  1408. X        /*
  1409. X        SetAPen(rp,PaperColor);
  1410. X        RectFill(rp,rp->cp_x, rp->cp_y-rp->TxBaseline, ow->Width - ow->window->BorderRight, rp->cp_y - rp->TxBaseline + rp->TxHeight,"move2",ow);
  1411. X        SetAPen(rp,PenColor);
  1412. X        */
  1413. X        ow->doc->pnum=pnum;
  1414. X        ow->doc->lnum=lnum;
  1415. X        }
  1416. X    }
  1417. X    }
  1418. X}
  1419. X
  1420. Xint
  1421. Xcurrentlinenum(doc)
  1422. X    struct doc *doc;
  1423. X{
  1424. X    int i,n=doc->lnum;
  1425. X    for(i=0;i<doc->pnum;i++) {
  1426. X    n+=doc->p[i].count;
  1427. X    }
  1428. X    return n;
  1429. X}
  1430. X
  1431. X
  1432. Xvoid
  1433. Xrefresh(ow)
  1434. X    struct openwindows *ow;
  1435. X{
  1436. X    int i,high;
  1437. X    struct paragraph *p;
  1438. X    u_short linenum;
  1439. X    u_short pnum;
  1440. X    int rightb, leftb, baseline, height;
  1441. X    struct RastPort *rp=ow->window->RPort;
  1442. X    high = ow->high;
  1443. X
  1444. X    if(ow->flags & ow_ICONIZED) return;
  1445. X
  1446. X    pnum=ow->doc->pnum;
  1447. X    p=&ow->doc->p[pnum];
  1448. X    linenum=ow->doc->lnum;
  1449. X    SetAPen(rp,PenColor);
  1450. X    SetBPen(rp,0);
  1451. X    SetDrMd(rp,JAM2);
  1452. X    rp->cp_y=ow->window->BorderTop + rp->TxBaseline;
  1453. X    leftb=ow->window->BorderLeft;
  1454. X    rightb=ow->Width - ow->window->BorderRight;
  1455. X    baseline=rp->TxBaseline;
  1456. X    height=rp->TxHeight;
  1457. X    for(i=0;i<high;i++) {
  1458. X    rp->cp_x= ow->window->BorderLeft;
  1459. X    displayline(rp,p,linenum,ow,0,0);
  1460. X    /* RectFill(rp,rp->cp_x, rp->cp_y-baseline, rightb, rp->cp_y - baseline + height -1 ,"refresh",ow); */
  1461. X    rp->cp_y += height;
  1462. X    linenum++;
  1463. X    if(linenum >= p->count) {
  1464. X        linenum=0;
  1465. X        pnum++;
  1466. X        if(pnum < ow->doc->p_count)
  1467. X        p=&ow->doc->p[pnum];
  1468. X        else
  1469. X        break; /* end of document */
  1470. X    }
  1471. X    }
  1472. X    SetAPen(rp,0);
  1473. X    RectFill(rp,
  1474. X    ow->window->BorderLeft,
  1475. X    rp->cp_y-baseline,
  1476. X    ow->Width - ow->window->BorderRight,
  1477. X    ow->Height - ow->window->BorderBottom,"refresh2",ow
  1478. X    );
  1479. X    SetAPen(rp,PenColor);
  1480. X}
  1481. X
  1482. Xint
  1483. Xsizewindow(win)
  1484. X    struct Window *win;
  1485. X{
  1486. X    struct openwindows
  1487. X       *ow=(struct openwindows *)win->UserData;
  1488. X    struct RastPort *rp=ow->window->RPort;
  1489. X    int wide, high;
  1490. X
  1491. X    /* ModifyIDCMP(im->IDCMPWindow, HELPWINDOWIDCMPFLAGS | SIZEVERIFY); */
  1492. X    if(rp->TxWidth==0 || rp->TxHeight==0) { /* DIVIDE BY ZERO!!!*/
  1493. X#ifdef DEBUG9
  1494. X    dmsg(9,"sizewindow: TxWidth==%ld TxHeight=%ld\n",rp->TxWidth, rp->TxHeight);
  1495. X#endif
  1496. X    goto fail;
  1497. X    }
  1498. X    if((ow->doc->linespace+ow->window->RPort->Font->tf_YSize)*3 < ow->Height) {
  1499. X    ow->window->RPort->TxHeight=ow->window->RPort->Font->tf_YSize+ow->doc->linespace;
  1500. X    } else {
  1501. X    ow->window->RPort->TxHeight=ow->window->RPort->Font->tf_YSize;
  1502. X    }
  1503. X    if(ow->doc->propwidth) {
  1504. X    /* wide = (ow->Width - win->BorderLeft - win->BorderRight)-rp->TxWidth; */
  1505. X    wide = (ow->Width - win->BorderLeft - win->BorderRight);
  1506. X    } else {
  1507. X    /* wide = (ow->Width - win->BorderLeft - win->BorderRight)/rp->TxWidth-1; */
  1508. X    wide = (ow->Width - win->BorderLeft - win->BorderRight)/rp->TxWidth;
  1509. X    }
  1510. X    high = (ow->Height- win->BorderTop - win->BorderBottom)/rp->TxHeight;
  1511. X
  1512. X    if(wide<5 || high<3 || wide>1024 || high >1024) goto fail;
  1513. X    if(wide != ow->wide) {
  1514. X#ifdef DEBUG1
  1515. X    /* dmsg(1,"wide=%ld, TxWidth=%ld\n",wide,rp->TxWidth); */
  1516. X#endif
  1517. X    ow->wide=wide;
  1518. X    if(format(ow->doc,(int)ow->wide,rp)==0) {
  1519. X#ifdef DEBUG1
  1520. X        dmsg(1,"FORMAT FAILED!\n");
  1521. X#endif
  1522. X        goto fail;
  1523. X    }
  1524. X    ow->doc->lnum=0;
  1525. X    }
  1526. X    if(ow->doc->lnum >= ow->doc->p[ow->doc->pnum].count) {
  1527. X    ow->doc->lnum=ow->doc->p[ow->doc->pnum].count;
  1528. X    if(ow->doc->lnum>0) ow->doc->lnum--;
  1529. X    }
  1530. X    if(ow->high>=ow->doc->l_count) { /* If doc < windowfull, move to top */
  1531. X    ow->doc->lnum=0;
  1532. X    ow->doc->pnum=0;
  1533. X    ow->high=0; /* Force fixgadget, just to be sure. */
  1534. X    }
  1535. X    if(high!=ow->high) {
  1536. X    ow->high=high;
  1537. X    fixscrollgadget(ow);
  1538. X    }
  1539. X    return (-1);
  1540. Xfail:
  1541. X    return 0;
  1542. X}
  1543. X
  1544. Xvoid
  1545. Xfixscrollgadget(ow)
  1546. X    struct openwindows *ow;
  1547. X{
  1548. X    long n=currentlinenum(ow->doc);
  1549. X    ULONG VPot, VBody;
  1550. X    struct PropInfo *p= (struct PropInfo *)ow->scroll->SpecialInfo;
  1551. X
  1552. X    if(p) {
  1553. X    if(ow->high >= ow->doc->l_count) {
  1554. X        VBody = -1;
  1555. X        VPot = 0;
  1556. X    } else {
  1557. X        if(ow->doc->l_count - ow->high <1) {
  1558. X#ifdef DEBUG9
  1559. X        dmsg(9,"OOOOOPPPS!! VBODY /%ld==error\n",ow->doc->l_count-ow->high);
  1560. X#endif
  1561. X        VBody=-1;
  1562. X        VPot=-1;
  1563. X        } else {
  1564. X        VBody= (long) (ow->high*0xffff) / (ow->doc->l_count) ;
  1565. X        VPot = (n<<16)/(ow->doc->l_count - ow->high) ;
  1566. X        if(VBody>0xffff) {
  1567. X            VBody=0xffff;
  1568. X        }
  1569. X        if(VPot>0xffff) {
  1570. X            VPot=0xffff;
  1571. X        }
  1572. X        }
  1573. X    }
  1574. X    ModifyProp(ow->scroll,ow->window,0,p->Flags,0,VPot,0,VBody);
  1575. X    }
  1576. X}
  1577. X
  1578. SHAR_EOF
  1579. echo "extracting oserr.c"
  1580. sed 's/^X//' << \SHAR_EOF > oserr.c
  1581. X/* HyperHelp -- Copyright 1989 Joe Porkka */
  1582. X
  1583. X/* oserr.c -- AmigaDOS Error messages + print error routine */
  1584. X
  1585. X#include <exec/types.h>
  1586. X#include <exec/nodes.h>
  1587. X#include "help.h"
  1588. Xstruct DOSerror errortext[]={
  1589. X    {103,"Out of memory"},
  1590. X    {121,"File is not an object module"},
  1591. X    {202,"Object in use"},
  1592. X    {203,"Object already exists"},
  1593. X    {204,"Directory not found"},
  1594. X    {205,"Object not found"},
  1595. X    {206,"Invalid window"},
  1596. X    {210,"Invalid file name"},
  1597. X    {212,"Object not of required type"},
  1598. X    {213,"Disk not validated"},
  1599. X    {214,"Disk is protected"},
  1600. X    {218,"Volume is not mounted"},
  1601. X    {221,"Disk is full"},
  1602. X    {223,"File is write protected"},
  1603. X    {224,"File is read protected"},
  1604. X    {225,"Not a DOS disk"},
  1605. X    {226,"No disk in drive"},
  1606. X    {209,"Invalid packet request type"},
  1607. X    {211,"Invalid object lock"},
  1608. X    {219,"Seek error"},
  1609. X    {232,"No more entries"},
  1610. X    {0,"Invalid error number"}
  1611. X};
  1612. X
  1613. Xerrnum(i)
  1614. X    int i;
  1615. X{
  1616. X    int j=0;
  1617. X    while(errortext[j].number!=0 && i!=errortext[j].number && j<100 )j++ ;
  1618. X    return(j);
  1619. X}
  1620. X
  1621. X
  1622. SHAR_EOF
  1623. echo "extracting print.c"
  1624. sed 's/^X//' << \SHAR_EOF > print.c
  1625. X/* HyperHelp -- Copyright 1989 Joe Porkka */
  1626. X
  1627. X/* print.c -- controls printer stuff */
  1628. X
  1629. X#include <exec/types.h>
  1630. X#include <exec/io.h>
  1631. X#include <intuition/intuition.h>
  1632. X#include <devices/printer.h>
  1633. X#include <devices/prtbase.h>
  1634. X
  1635. X/* long stdout,oserr,input; */
  1636. X/* #define INBUFLEN 64 */
  1637. X/* char inbuf[INBUFLEN]; */
  1638. Xstruct IOStdReq *printreq, *CreateExtIO();
  1639. X/* struct MsgPort *mp, *CreatePort(); */
  1640. X/* long debug; */
  1641. X
  1642. X/*
  1643. Xvoid
  1644. Xmain(av,ac)
  1645. X    int av;
  1646. X    char *ac;
  1647. X{
  1648. X    int i, wide, high;
  1649. X    int len;
  1650. X
  1651. X    mp=0; printreq=0;
  1652. X    debug=1;
  1653. X    stdout=Open("CON:0/0/600/170/NOTHING",1005);
  1654. X    input=Open(":test",1005);
  1655. X    if((stdout==0) || (input==0)) goto fail;
  1656. X    if( (mp=CreatePort(0,0))==0) {
  1657. X    printf("Could not Allocate a Port.");
  1658. X    goto fail;
  1659. X    }
  1660. X    if(printinit(mp)==0) goto fail;
  1661. X    getprintwidth(&wide, &high);
  1662. X    if(wide==0) {
  1663. X    printf("Width==0\n");
  1664. X    goto fail;
  1665. X    }
  1666. X    printf("Width=%ld high=%ld\n",wide,high);
  1667. X    printit("Margins are now set. This is a long long to force it to wrap around. I hope that it does.\n");
  1668. X    WaitPort(mp);
  1669. X    GetMsg(mp);
  1670. X    printit("\033#3Margins are now unset. This is a long long to force it to wrap around. I hope that it does.\n");
  1671. X    WaitPort(mp);
  1672. X    GetMsg(mp);
  1673. X    printf("Width=%ld high=%ld\n",wide,high);
  1674. X    len=Read(input,inbuf,INBUFLEN);
  1675. X    for(i=0;len;i++) {
  1676. X    inbuf[len]=0;
  1677. X    printit(inbuf);
  1678. X    printf("Now, reading data\n");
  1679. X    len=Read(input,inbuf,INBUFLEN);
  1680. X    printf("Now, waiting for reply...");
  1681. X    WaitPort(mp);
  1682. X    GetMsg(mp);
  1683. X    printf("done. Error=%ld, Actual=%ld.\n\n",printreq->io_Error, printreq->io_Actual);
  1684. X    }
  1685. X
  1686. Xfail:
  1687. X    printf("Now closeing down.IoErr=%ld\n",IoErr());
  1688. X    printdnit();
  1689. X    if(mp) {
  1690. X    DeletePort(mp);
  1691. X    mp=0;
  1692. X    }
  1693. X    if(input) {
  1694. X    if(stdout) printf("Closing main.c\n");
  1695. X    Close(input);
  1696. X    input=0;
  1697. X    }
  1698. X    if(stdout) {
  1699. X    printf("This is the last thing that main will do!!\nPress Return\n");
  1700. X    Read(stdout,"buffer",1);
  1701. X    Close(stdout);
  1702. X    }
  1703. X    stdout=0;
  1704. X}
  1705. X*/
  1706. X
  1707. Xprintit(string)
  1708. X    char *string;
  1709. X{
  1710. X    printreq->io_Command=CMD_WRITE;
  1711. X    printreq->io_Data=(APTR)string;
  1712. X    printreq->io_Length=-1; /* Write till NULL byte */
  1713. X    SendIO(printreq);
  1714. X}
  1715. X
  1716. Xprintdnit()
  1717. X{
  1718. X    if(printreq) {
  1719. X    CloseDevice(printreq);
  1720. X    DeleteExtIO(printreq);
  1721. X    printreq=0;
  1722. X    }
  1723. X}
  1724. Xint
  1725. Xprintinit(mp)
  1726. X    struct MsgPort *mp;
  1727. X{
  1728. X    printreq=CreateExtIO(mp,sizeof(struct IOStdReq));
  1729. X    if(printreq==0) {
  1730. X    dmsg(5,"Could not create stdreq\n");
  1731. X    return(0);
  1732. X    }
  1733. X    if(OpenDevice("printer.device",0,printreq,0)!=0) {
  1734. X    dmsg(5,"Could not open printer.device!\n");
  1735. X    DeleteExtIO(printreq);
  1736. X    printreq=0;
  1737. X    return 0;
  1738. X    }
  1739. X    return -1;
  1740. X}
  1741. Xgetprintwidth(width, height)
  1742. X    int *width, *height;
  1743. X{
  1744. X    struct Preferences *prefs;
  1745. X
  1746. X    *width=*height=0;
  1747. X    if(printreq->io_Device==0) {
  1748. X    dmsg(5,"Print io_Device==0!!\n");
  1749. X    return ;
  1750. X    }
  1751. X    prefs= &((struct PrinterData *)printreq->io_Device)->pd_Preferences;
  1752. X    if(prefs) {
  1753. X    *width =  prefs->PrintRightMargin - prefs->PrintLeftMargin;
  1754. X    *height = prefs->PaperLength;
  1755. X    }
  1756. X}
  1757. SHAR_EOF
  1758. echo "extracting source.readme"
  1759. sed 's/^X//' << \SHAR_EOF > source.readme
  1760. XHere is the source code to HyperHelp.
  1761. X
  1762. XIt is copyright 1989 Joe  Porkka, but is freely
  1763. Xdistributable in its unmodified form.
  1764. XIf you want it for commercial purposes please contact me.
  1765. X
  1766. XNote to Fred Fish: I'd be honored to have you include this
  1767. X           on one of your disks.
  1768. X
  1769. XIf you like it, please send me money. If I get enough
  1770. Xmoney I could buy some extra hardware to help development of improved
  1771. Xversions of Hyperhelp.
  1772. X
  1773. X
  1774. XPlease send suggestions and bug reports to
  1775. X        porkka@frith.egr.msu.edu
  1776. X        or to
  1777. X        Joe Porkka
  1778. X        745 Burcham #79
  1779. X        East Lansing Mi, 48823
  1780. X        (517) 337-9472
  1781. SHAR_EOF
  1782. echo "extracting style.h"
  1783. sed 's/^X//' << \SHAR_EOF > style.h
  1784. X/* HyperHelp -- Copyright 1989 Joe Porkka */
  1785. X
  1786. X/* style.h  --    The STYLE_#? defines */
  1787. X
  1788. X/* Used by:
  1789. X    findwordinline.c
  1790. X    format.c
  1791. X    displayline.c
  1792. X    getfile.c
  1793. X*/
  1794. X
  1795. X#define NCOM          15
  1796. X#define STYLE_REF     128
  1797. X#define STYLE_EXEC     129
  1798. X#define STYLE_UNREF     130
  1799. X#define STYLE_OFFSET    (STYLE_UNREF+1)
  1800. X
  1801. X#define STYLE_NORMAL    (STYLE_UNREF+1)
  1802. X#define STYLE_UNDERLINE (STYLE_UNREF+2)
  1803. X#define STYLE_BOLD    (STYLE_UNREF+3)
  1804. X#define STYLE_ITALIC    (STYLE_UNREF+4)
  1805. X#define STYLE_COLOR    (STYLE_UNREF+5)
  1806. X#define STYLE_FONT    (STYLE_UNREF+6)
  1807. X#define STYLE_WINDOW    (STYLE_UNREF+7)
  1808. X#define STYLE_TITLE    (STYLE_UNREF+8)
  1809. X#define STYLE_LSPACE    (STYLE_UNREF+9)
  1810. X#define STYLE_INDENT    (STYLE_UNREF+10)
  1811. X#define STYLE_LABEL    (STYLE_UNREF+11)
  1812. X#define STYLE_PINDENT    (STYLE_UNREF+12)
  1813. X#define STYLE_LAST    (STYLE_UNREF+12)
  1814. X#define STYLE_INVALID     0xff
  1815. SHAR_EOF
  1816. echo "extracting tokens.c"
  1817. sed 's/^X//' << \SHAR_EOF > tokens.c
  1818. X/* HyperHelp -- Copyright 1989 Joe Porkka */
  1819. X
  1820. X/* tokens.c  -- the tokens and the token finder */
  1821. X
  1822. X#include "df0:tf/new/style.h"
  1823. X
  1824. Xtypedef unsigned char u_char;
  1825. Xtypedef unsigned long u_long;
  1826. X
  1827. Xstatic char *(commands[NCOM]) = {
  1828. X    "ref",
  1829. X    "execute",
  1830. X    "unref",
  1831. X    "normal",
  1832. X    "underline",
  1833. X    "bold",
  1834. X    "italic",
  1835. X    "color",
  1836. X    "font",
  1837. X    "window",
  1838. X    "title",
  1839. X    "lspace",
  1840. X    "indent",
  1841. X    "label",
  1842. X    "pindent"
  1843. X};
  1844. X
  1845. X
  1846. Xu_char
  1847. Xtoken(ptr,len)
  1848. X    u_char *ptr;
  1849. X    u_long len;
  1850. X{
  1851. X    int i;
  1852. X
  1853. X    for(i=0;i<NCOM;i++) {
  1854. X    if(strnicmp(commands[i],ptr,len)==0){
  1855. X        /* dmsg(1,"MATCHED '%s'\n",commands[i]); */
  1856. X        return (u_char)(128+i);
  1857. X    }
  1858. X    }
  1859. X    /* dmsg(1,"FAILED\n"); */
  1860. X    return (u_char) 0;
  1861. X}
  1862. X
  1863. SHAR_EOF
  1864. echo "extracting windows.c"
  1865. sed 's/^X//' << \SHAR_EOF > windows.c
  1866. X/* HyperHelp -- Copyright 1989 Joe Porkka */
  1867. X
  1868. X/* windows.c -- Manages the windows directly. Controls open, close, sizeing
  1869. X        and refreshing damaged areas.
  1870. X*/
  1871. X
  1872. X#include <intuition/intuition.h>
  1873. X#include <exec/memory.h>
  1874. X#include <libraries/dosextens.h>
  1875. X#include <graphics/gfxbase.h>
  1876. X#include "help.h"
  1877. X#include "helptext.h"
  1878. X#define DEBUG1
  1879. X
  1880. Xextern long IntuitionBase, GfxBase, DiskfontBase;
  1881. Xextern struct MsgPort *mp, *CreatePort();
  1882. Xextern struct Task *mytask; /* Defined in getfile.c*/
  1883. Xextern int debug;
  1884. Xextern struct IOStdReq *printreq;
  1885. Xextern int printing;
  1886. X
  1887. X/* ENV: Vars */
  1888. Xextern int ScreenType, NoHotKey, PenColor;
  1889. Xextern int ENVTop, ENVLeft, ENVWidth, ENVHeight, ENVXInc, ENVYInc;
  1890. Xextern ULONG ENVRefresh;
  1891. X/**/
  1892. X
  1893. Xint TOP,LEFT,WIDTH,HEIGHT,XINC,YINC;
  1894. X
  1895. Xstruct List windowhead;
  1896. Xstatic short WBscreenWIDTH, WBscreenHEIGHT, WBscreenDETAIL, WBscreenBLOCK, WBscreenBARHEIGHT;
  1897. Xshort screenWIDTH, screenHEIGHT, screenBARHEIGHT; /* Our screen, whether it be custom or WBENCH */
  1898. X
  1899. Xstruct Process *myproc;
  1900. Xshort windowcount;
  1901. Xstruct NewWindow nw;
  1902. Xstruct Screen *screen, *OpenScreen(struct NewScreen *);
  1903. Xstruct NewScreen ns = {
  1904. X    0,0,640,STDSCREENHEIGHT,2,-1,-1,HIRES,CUSTOMSCREEN,0,"Help Screen",0,0
  1905. X};
  1906. X
  1907. X/* These only get used if getborders() cannot open a test window */
  1908. X#define DEFAULTBORDER_TOP 11
  1909. X#define DEFAULTBORDER_BOT 10
  1910. X#define DEFAULTBORDER_LEFT 4
  1911. X#define DEFAULTBORDER_RIGHT 18
  1912. X/* Dimensions of the test window */
  1913. X#define TESTWIDE 100
  1914. X#define TESTHIGH 50
  1915. X
  1916. Xstatic int borderTOP, borderBOT, borderLEFT, borderRIGHT;
  1917. X
  1918. Xint
  1919. Xwindowinit()
  1920. X{
  1921. X    struct Screen *testscreen;
  1922. X    struct GfxBase *gb=(struct GfxBase *)GfxBase;
  1923. X    int test;
  1924. X
  1925. X    if(ENVRefresh==0) {
  1926. X#ifdef DEBUG1
  1927. X    dmsg(1,"SIMPLE_REFRESH has been selected.\n");
  1928. X#endif
  1929. X    ENVRefresh = SIMPLE_REFRESH;
  1930. X    } else {
  1931. X#ifdef DEBUG1
  1932. X    dmsg(1,"SMART_REFRESH has been selected.\n");
  1933. X#endif
  1934. X    ENVRefresh = SMART_REFRESH;
  1935. X    }
  1936. X
  1937. X    screenWIDTH=WBscreenWIDTH=0;
  1938. X    screenHEIGHT=WBscreenHEIGHT=0 ;
  1939. X
  1940. X    windowhead.lh_Head= (struct Node *)&windowhead.lh_Tail;
  1941. X    windowhead.lh_TailPred= (struct Node *)&windowhead.lh_Head;
  1942. X    windowhead.lh_Tail=0;
  1943. X    windowhead.lh_Type=HELPWINDOWLIST;
  1944. X
  1945. X    testscreen=(struct Screen *)AllocMem(sizeof(struct Screen),MEMF_CLEAR);
  1946. X    test=GetScreenData(testscreen,sizeof(struct Screen),WBENCHSCREEN,0);
  1947. X    WBscreenWIDTH=screenWIDTH= gb-> NormalDisplayColumns;
  1948. X    WBscreenHEIGHT=screenHEIGHT= gb->NormalDisplayRows;
  1949. X    if(test!=0) {
  1950. X    /*
  1951. X    WBscreenWIDTH=screenWIDTH=testscreen->Width;
  1952. X    WBscreenHEIGHT=screenHEIGHT=testscreen->Height;
  1953. X    */
  1954. X    WBscreenBARHEIGHT=screenBARHEIGHT=testscreen->BarHeight;
  1955. X    if(screenWIDTH<150 || screenHEIGHT<75) { /* Too small of a screen */
  1956. X        test=0;
  1957. X    } else {
  1958. X        WBscreenDETAIL=testscreen->DetailPen;
  1959. X        WBscreenBLOCK=testscreen->BlockPen;
  1960. X        /* Make sure things are withen bounds. If they are not
  1961. X           then try to fix the reasonably.
  1962. X        */
  1963. X        if(ENVWidth<100  || ENVWidth >screenWIDTH) ENVWidth=screenWIDTH;
  1964. X        if(ENVHeight<50 || ENVHeight>screenHEIGHT)ENVHeight=screenHEIGHT-testscreen->BarHeight-2;
  1965. X        if(ENVLeft+ENVWidth>screenWIDTH || ENVLeft<0) ENVLeft=0;
  1966. X        if(ENVTop+ENVHeight>screenHEIGHT || ENVTop<0) ENVTop=testscreen->BarHeight;
  1967. X        if(ENVLeft+ENVWidth>screenWIDTH) {
  1968. X        if(screenWIDTH-ENVLeft<100) { /* Too narrow */
  1969. X            ENVLeft=0;
  1970. X            ENVWidth=screenWIDTH/2;
  1971. X        } else ENVWidth=screenWIDTH-ENVLeft;
  1972. X        if(ENVWidth<100) ENVWidth=100; /* Something better should be done for this... */
  1973. X        }
  1974. X        if(ENVTop+ENVHeight>screenHEIGHT) {
  1975. X        if(screenHEIGHT-ENVTop<50) {
  1976. X            ENVTop=testscreen->BarHeight;
  1977. X            ENVHeight=screenHEIGHT/2;
  1978. X        } else ENVHeight=screenHEIGHT-ENVTop;
  1979. X        if(ENVHeight<50) ENVHeight=50; /* again, something better ... */
  1980. X        }
  1981. X        if(ENVXInc<0 || ENVXInc>screenWIDTH) ENVXInc=5;
  1982. X        if(ENVYInc<0 || ENVYInc>screenHEIGHT) ENVYInc=testscreen->BarHeight;
  1983. X        if(ENVXInc==0 && ENVYInc==0) {
  1984. X        ENVXInc=5;
  1985. X        ENVYInc=testscreen->BarHeight;
  1986. X        }
  1987. X    }
  1988. X    }
  1989. X    LEFT=ENVLeft;
  1990. X    TOP=ENVTop;
  1991. X
  1992. X    WIDTH=ENVWidth;
  1993. X    HEIGHT=ENVHeight;
  1994. X    XINC=ENVXInc;
  1995. X    YINC=ENVYInc;
  1996. X
  1997. X    if(testscreen) FreeMem(testscreen,sizeof(struct Screen));
  1998. X    if(test==0) {
  1999. X#ifdef DEBUG5
  2000. X    dmsg(5,"Could not get screen info!!!\n");
  2001. X#endif
  2002. X    return(0);
  2003. X    }
  2004. X    return (-1);
  2005. X}
  2006. X
  2007. Xvoid
  2008. Xcustomscreen() {
  2009. X    screenWIDTH  = WBscreenWIDTH; /* fail-safe DEFAULTS */
  2010. X    screenHEIGHT = WBscreenHEIGHT;
  2011. X    screenBARHEIGHT = WBscreenBARHEIGHT;
  2012. X
  2013. X    ns.Height=STDSCREENHEIGHT;
  2014. X    ns.Width=WBscreenWIDTH;
  2015. X    ns.DetailPen=WBscreenDETAIL;
  2016. X    ns.BlockPen=WBscreenBLOCK;
  2017. X    ns.ViewModes = HIRES;
  2018. X    if(ScreenType & 2) ns.ViewModes |= LACE;
  2019. X    screen=OpenScreen(&ns);
  2020. X    if(screen) {
  2021. X    screenHEIGHT=screen->Height;
  2022. X    screenWIDTH=screen->Width; /* Just to be sure... */
  2023. X    screenBARHEIGHT=screen->BarHeight;
  2024. X    }
  2025. X}
  2026. X
  2027. Xvoid
  2028. XCWS(win,font)
  2029. X    struct Window *win;
  2030. X    struct TextFont *font;
  2031. X{
  2032. X    struct MsgPort *mp = (struct MsgPort *)win->UserPort;
  2033. X    struct IntuiMessage *im, *succ;
  2034. X
  2035. X    if(win==0) {
  2036. X    return;
  2037. X    }
  2038. X    removemenu(win);
  2039. X    Forbid();
  2040. X    im = (struct IntuiMessage *)mp->mp_MsgList.lh_Head;
  2041. X    while ( succ=(struct IntuiMessage *)im->ExecMessage.mn_Node.ln_Succ ) {
  2042. X       if ( im->IDCMPWindow == win ) {
  2043. X      Remove ( im );
  2044. X      ReplyMsg( im );
  2045. X       }
  2046. X       im = succ;
  2047. X    }
  2048. X    win->UserPort = 0;
  2049. X    ModifyIDCMP( win, 0L );
  2050. X    Permit();
  2051. X    CloseWindow( win );
  2052. X    if(font) CloseFont(font);
  2053. X}
  2054. X
  2055. Xvoid
  2056. Xclosewindowsafely(ow)
  2057. X    struct openwindows *ow;
  2058. X{
  2059. X#ifdef DEBUG1
  2060. X    dmsg(1,"cws doing CWS...");
  2061. X#endif
  2062. X    CWS(ow->window,ow->doc->savefont);
  2063. X#ifdef DEBUG1
  2064. X    dmsg(1,"done.\n");
  2065. X#endif
  2066. X    ow->doc->savefont=0;
  2067. X    if( !(ow->flags & ow_PRINTING)) {
  2068. X    if(windowcount>0)
  2069. X        windowcount--;
  2070. X    else
  2071. X#ifdef DEBUG9
  2072. X        dmsg(9,"WINDOWCOUNT==%ld during closewindowsafely!\n",windowcount);
  2073. X#endif
  2074. X    if(windowcount==0 && screen) {
  2075. X        CloseScreen(screen);
  2076. X        screen=0;
  2077. X    }
  2078. X    if(ow->scroll) {
  2079. X#ifdef DEBUG1
  2080. X        dmsg(1,"Freeing gadgets1...");
  2081. X#endif
  2082. X        if(ow->scroll->SpecialInfo) FreeMem(ow->scroll->SpecialInfo,sizeof(struct PropInfo));
  2083. X        if(ow->scroll->GadgetRender) FreeMem(ow->scroll->GadgetRender,sizeof(struct Image));
  2084. X        FreeMem(ow->scroll,sizeof(struct Gadget));
  2085. X        ow->scroll=0;
  2086. X#ifdef DEBUG1
  2087. X        dmsg(1,"done.\n");
  2088. X#endif
  2089. X    }
  2090. X    if(ow->up) {
  2091. X#ifdef DEBUG1
  2092. X        dmsg(1,"Freeing gadgets2...");
  2093. X#endif
  2094. X        if(ow->up->GadgetRender) FreeMem(ow->up->GadgetRender,sizeof(struct Image));
  2095. X        FreeMem( ow->up,sizeof(struct Gadget));
  2096. X        ow->up=0;
  2097. X#ifdef DEBUG1
  2098. X        dmsg(1,"done.\n");
  2099. X#endif
  2100. X    }
  2101. X    if(ow->down) {
  2102. X#ifdef DEBUG1
  2103. X        dmsg(1,"Freeing gadgets3...");
  2104. X#endif
  2105. X        if(ow->down->GadgetRender) FreeMem(ow->down->GadgetRender,sizeof(struct Image));
  2106. X        FreeMem(ow->down,sizeof(struct Gadget));
  2107. X        ow->down=0;
  2108. X#ifdef DEBUG1
  2109. X        dmsg(1,"done.\n");
  2110. X#endif
  2111. X    }
  2112. X    if(ow->icon) {
  2113. X#ifdef DEBUG1
  2114. X        dmsg(1,"Freeing gadgets4...");
  2115. X#endif
  2116. X        if(ow->icon->GadgetRender) FreeMem(ow->icon->GadgetRender,sizeof(struct Image));
  2117. X        FreeMem(ow->icon,sizeof(struct Gadget));
  2118. X        ow->icon=0;
  2119. X#ifdef DEBUG1
  2120. X        dmsg(1,"done.\n");
  2121. X#endif
  2122. X    }
  2123. X    }
  2124. X}
  2125. X
  2126. X/* This function is supposed to get sizeof(window borders).
  2127. X   There is no particularly good way of doing this with
  2128. X   version 1.3 of AmigaOS. So we default for now and
  2129. X   patiently await version 1.4....
  2130. X*/
  2131. Xvoid
  2132. Xgetborders()
  2133. X{
  2134. X    /* int test; */
  2135. X    /* int i; */
  2136. X    /* struct Screen *testscreen=(struct Screen *)AllocMem(sizeof(struct Screen),MEMF_CLEAR); */
  2137. X
  2138. X    /* Set up the the defaults in case anything fails */
  2139. X    borderTOP    = DEFAULTBORDER_TOP;
  2140. X    borderBOT    = DEFAULTBORDER_BOT;
  2141. X    borderLEFT    = DEFAULTBORDER_LEFT;
  2142. X    borderRIGHT = DEFAULTBORDER_RIGHT;
  2143. X
  2144. X    /*
  2145. X#ifdef DEBUG1
  2146. X    dmsg(1,"GETTING borders");
  2147. X#endif
  2148. X    if(testscreen==0) return; /* May as well give up now */
  2149. X
  2150. X    if(screen==0) { /* Then, get wbenchscreen data */
  2151. X    test=GetScreenData(testscreen,sizeof(struct Screen),WBENCHSCREEN,0);
  2152. X    } else { /* Else get custom screen data */
  2153. X    test=GetScreenData(testscreen,sizeof(struct Screen),CUSTOMSCREEN,screen);
  2154. X    }
  2155. X
  2156. X#ifdef DEBUG1
  2157. X    dmsg(1,"\nGot screen info, test=%ld",test);
  2158. X#endif
  2159. X    if(test==0) goto fail; /* Could not get data, don't open our screen */
  2160. X
  2161. X    borderTOP=testscreen->WBorTop;
  2162. X    borderBOT=testscreen->WBorBottom;
  2163. X    borderLEFT=testscreen->WBorLeft;
  2164. X    borderRIGHT=testscreen->WBorRight;
  2165. X#ifdef DEBUG1
  2166. X    dmsg(1,"Window borders are Top=%ld, Bot=%ld, Left=%ld, Right=%ld\n",
  2167. X    borderTOP,
  2168. X    borderBOT,
  2169. X    borderLEFT,
  2170. X    borderRIGHT
  2171. X    );
  2172. X#endif
  2173. Xfail:
  2174. X#ifdef DEBUG1
  2175. X    dmsg(1,"\ntestscreen=%ld.\n",testscreen);
  2176. X#endif
  2177. X    if(testscreen) FreeMem(testscreen,sizeof(struct Screen));
  2178. X    */
  2179. X}
  2180. X
  2181. Xstruct Window *
  2182. Xmakewindow(ow,x,y,width,height,title, myfont)
  2183. X    struct openwindows *ow;
  2184. X    int x,y,width,height;
  2185. X    u_char *title;
  2186. X    struct TextAttr *myfont;
  2187. X{
  2188. X    USHORT *upimage, *downimage, *iconimage;
  2189. X    struct TextFont *font, *diskfont, *OpenFont(), *OpenDiskFont();
  2190. X    struct Window *win, *OpenWindow();
  2191. X    struct Gadget *vertbar=0, *uparrow=0, *downarrow=0, *icon=0;
  2192. X    struct Gadget *tmp;
  2193. X    struct PropInfo *pinfo;
  2194. X    struct Image *image, *image2, *image3;
  2195. X    struct Window *tmpwindow;
  2196. X    int test;
  2197. X
  2198. X    ow->Width=width;
  2199. X    ow->Height=height;
  2200. X    getimages(&upimage,&downimage,&iconimage);
  2201. X    if(ScreenType!=0 && windowcount==0) customscreen();
  2202. X    if(windowcount==0) getborders();
  2203. X
  2204. X    if( (vertbar=(struct Gadget*)AllocMem(sizeof(struct Gadget),MEMF_CLEAR|MEMF_NAMED,"makewindow1"))==0)
  2205. X    goto fail;
  2206. X    if( (vertbar->SpecialInfo=(APTR)( pinfo=(struct PropInfo *)AllocMem(sizeof(struct PropInfo),MEMF_CLEAR|MEMF_NAMED,"makewindow2")))==0)
  2207. X    goto fail;
  2208. X    if( (vertbar->GadgetRender=(APTR)AllocMem(sizeof(struct Image),MEMF_CLEAR|MEMF_NAMED,"makewindow3"))==0)
  2209. X    goto fail;
  2210. X
  2211. X    if( (uparrow=(struct Gadget*)AllocMem(sizeof(struct Gadget),MEMF_CLEAR|MEMF_NAMED,"makewindow4"))==0)
  2212. X    goto fail;
  2213. X    if( (image=(struct Image *)AllocMem(sizeof(struct Image),MEMF_CLEAR|MEMF_NAMED,"makewindow5"))==0)
  2214. X    goto fail;
  2215. X    uparrow->GadgetRender=(APTR)image;
  2216. X    if( (downarrow=(struct Gadget*)AllocMem(sizeof(struct Gadget),MEMF_CLEAR|MEMF_NAMED,"makewindow6"))==0)
  2217. X    goto fail;
  2218. X    if( (image2=(struct Image *)AllocMem(sizeof(struct Image),MEMF_CLEAR|MEMF_NAMED,"makewindow7"))==0)
  2219. X    goto fail;
  2220. X    downarrow->GadgetRender=(APTR)image2;
  2221. X
  2222. X    if( (icon=(struct Gadget*)AllocMem(sizeof(struct Gadget),MEMF_CLEAR|MEMF_NAMED,"makewindowicon1"))==0)
  2223. X    goto fail;
  2224. X    if( (image3=(struct Image *)AllocMem(sizeof(struct Image),MEMF_CLEAR|MEMF_NAMED,"makewindowicon2"))==0)
  2225. X    goto fail;
  2226. X    icon->GadgetRender=(APTR)image3;
  2227. X
  2228. X    vertbar->NextGadget=uparrow;
  2229. X    vertbar->LeftEdge= -borderRIGHT+3 ;
  2230. X    vertbar->TopEdge= borderTOP;
  2231. X    vertbar->Width= borderRIGHT-4;
  2232. X    vertbar->Height = -borderTOP - borderBOT -16 -2; /* 16=the height of the arrows */
  2233. X
  2234. X    vertbar->Flags= GADGHNONE | GADGIMAGE | GRELRIGHT | GRELHEIGHT;
  2235. X    vertbar->Activation = GADGIMMEDIATE | FOLLOWMOUSE | RIGHTBORDER;
  2236. X    vertbar->GadgetType = PROPGADGET;
  2237. X    vertbar->GadgetID=SCROLLBAR;
  2238. X    pinfo->Flags = AUTOKNOB | FREEVERT ;
  2239. X    pinfo->HorizPot=65535;
  2240. X    pinfo->VertPot=65535;
  2241. X    pinfo->HorizBody=65535;
  2242. X    pinfo->VertBody=65535;
  2243. X
  2244. X    uparrow->NextGadget=downarrow;
  2245. X    uparrow->LeftEdge= -borderRIGHT+3;
  2246. X    uparrow->TopEdge=-borderBOT-8-8;
  2247. X    uparrow->Width=14;
  2248. X    uparrow->Height=8;
  2249. X    uparrow->Flags= GADGHCOMP | GADGIMAGE | GRELRIGHT | GRELBOTTOM;
  2250. X    uparrow->Activation = RELVERIFY | GADGIMMEDIATE | RIGHTBORDER;
  2251. X    uparrow->GadgetType = BOOLGADGET;
  2252. X    uparrow->GadgetID=UPARROW;
  2253. X    image->LeftEdge=0;
  2254. X    image->TopEdge=-1;
  2255. X    image->Width=14;
  2256. X    image->Height=10;
  2257. X    image->Depth=1;
  2258. X    image->ImageData=upimage;
  2259. X
  2260. X    image->PlanePick=1;
  2261. X    image->PlaneOnOff=0;
  2262. X
  2263. X    downarrow->NextGadget=0;
  2264. X    downarrow->LeftEdge= -borderRIGHT+3;
  2265. X    downarrow->TopEdge= -borderBOT-8+2;
  2266. X    downarrow->Width=14;
  2267. X    downarrow->Height=8;
  2268. X    downarrow->Flags= GADGHCOMP | GADGIMAGE | GRELRIGHT | GRELBOTTOM;
  2269. X    downarrow->Activation = GADGIMMEDIATE | RELVERIFY | RIGHTBORDER;
  2270. X    downarrow->GadgetType = BOOLGADGET;
  2271. X    downarrow->GadgetID=DOWNARROW;
  2272. X    image2->LeftEdge=0;
  2273. X    image2->TopEdge=-1;
  2274. X    image2->Width=14;
  2275. X    image2->Height=9;
  2276. X    image2->Depth=1;
  2277. X    image2->ImageData=downimage;
  2278. X
  2279. X    image2->PlanePick=1;
  2280. X    image2->PlaneOnOff=0;
  2281. X
  2282. X    icon->NextGadget=0;
  2283. X    icon->LeftEdge= -borderRIGHT-60;
  2284. X    icon->TopEdge= 0;
  2285. X    icon->Width=24;
  2286. X    icon->Height=10;
  2287. X    icon->Flags= GADGHCOMP | GADGIMAGE | GRELRIGHT ;
  2288. X    icon->Activation = GADGIMMEDIATE | RELVERIFY | TOPBORDER;
  2289. X    icon->GadgetType = BOOLGADGET;
  2290. X    icon->GadgetID=ICONWINDOW;
  2291. X    image3->LeftEdge=0;
  2292. X    image3->TopEdge=0;
  2293. X    image3->Width=28;
  2294. X    image3->Height=10;
  2295. X    image3->Depth=2;
  2296. X    image3->ImageData=iconimage;
  2297. X
  2298. X    image3->PlanePick=3;
  2299. X    image3->PlaneOnOff=0;
  2300. X
  2301. X    nw.LeftEdge=x;
  2302. X    nw.TopEdge=y;
  2303. X    if(width <10*8+borderLEFT+borderRIGHT || height < 3*8+borderTOP+borderBOT) {
  2304. X    dmsg(9,"border stuff screwed up!");
  2305. X    dmsg(9,"width <10*8+LEFT+RIGHT (%ld<10*8+%ld+%ld) || height <3*8+TOP+BOT (%ld < 3*8+%ld+%ld.\n",width,borderLEFT,borderRIGHT,height,borderTOP,borderBOT);
  2306. X    goto fail;
  2307. X    }
  2308. X    nw.Width=width;
  2309. X    nw.Height=height;
  2310. X    nw.DetailPen= -1;
  2311. X    nw.BlockPen= -1;
  2312. X    nw.IDCMPFlags=0;
  2313. X    nw.Flags=HELPWINDOWFLAGS | ENVRefresh;
  2314. X    nw.CheckMark=0;
  2315. X    nw.Title=title;
  2316. X    nw.Screen=screen;
  2317. X    nw.BitMap=0;
  2318. X    nw.MinWidth=nw.Width;
  2319. X    nw.MinHeight=nw.Height;
  2320. X    nw.MaxWidth = -1; nw.MaxHeight = -1;
  2321. X    if(screen)
  2322. X    nw.Type=CUSTOMSCREEN;
  2323. X    else
  2324. X    nw.Type=WBENCHSCREEN;
  2325. X    nw.FirstGadget=vertbar;
  2326. X
  2327. X    win=OpenWindow(&nw);
  2328. X    if(win==0) {
  2329. X    dmsg(9,"Window would not open!\n");
  2330. X    goto fail;
  2331. X    }
  2332. X    AddGadget(win,icon,0);      /* Put the ICON gadget at the head of the class */
  2333. X    RefreshGList(icon,win,0,1); /* ...and make it appear */
  2334. X    myproc=(struct Process *)mytask;
  2335. X    tmpwindow=(struct Window *)myproc->pr_WindowPtr;
  2336. X    myproc->pr_WindowPtr=(APTR)win;
  2337. X    ScreenToFront(win->WScreen);
  2338. X    win->UserPort=mp;
  2339. X    ModifyIDCMP(win,HELPWINDOWIDCMPFLAGS);
  2340. X    windowcount++;
  2341. X    ow->window=win;
  2342. X    font=0;
  2343. X    if(myfont->ta_YSize) {
  2344. X#ifdef DEBUG1
  2345. X    dmsg(1,"OpenFont(myfont)\n");
  2346. X#endif
  2347. X    font=OpenFont(myfont);
  2348. X    if (font==0 || font->tf_YSize!=myfont->ta_YSize) {
  2349. X        if(DiskfontBase==0) {
  2350. X#ifdef DEBUG1
  2351. X        dmsg(1,"OpenLibrary(\"diskfont.library\",0)\n");
  2352. X#endif
  2353. X        DiskfontBase=OpenLibrary("diskfont.library",0);
  2354. X        }
  2355. X        if(DiskfontBase) {
  2356. X#ifdef DEBUG1
  2357. X        dmsg(1,"OpenDiskFont\n");
  2358. X#endif
  2359. X        diskfont=OpenDiskFont(myfont);
  2360. X        if(diskfont) {
  2361. X            if(font)CloseFont(font);
  2362. X            font=diskfont;
  2363. X        }
  2364. X        CloseLibrary(DiskfontBase);
  2365. X        DiskfontBase=0;
  2366. X        }
  2367. X    }
  2368. X    }
  2369. X    if(font) {
  2370. X    dmsg(1,"font.y=%ld, requested=%ld\n",font->tf_YSize,myfont->ta_YSize);
  2371. X    SetFont(win->RPort,font);
  2372. X    ow->doc->savefont=font;
  2373. X    }
  2374. X    SetDrMd(win->RPort,JAM1);
  2375. X    ow->savewide=borderLEFT+borderRIGHT+win->RPort->TxWidth * strlen(win->Title) + 76;
  2376. X    if(ow->savewide + 15 > win->WScreen->Width) ow->savewide=win->WScreen->Width - 30;
  2377. X    ow->savehigh=screenBARHEIGHT;
  2378. X    ow->saveleft=nw.LeftEdge+ENVXInc;
  2379. X    ow->savetop=nw.TopEdge+ENVYInc;
  2380. X    if(ow->saveleft+ow->savewide > win->WScreen->Width) ow->saveleft=0;
  2381. X    if(ow->savetop+ow->savehigh > win->WScreen->Height) ow->savetop=win->WScreen->BarHeight;
  2382. X
  2383. X    tmp=win->FirstGadget;
  2384. X
  2385. X    if(win->RPort->Font->tf_Flags & FPF_PROPORTIONAL) {
  2386. X    int i,j,k;
  2387. X    char *test="AbciOiO";
  2388. X    int lowc=win->RPort->Font->tf_LoChar;
  2389. X
  2390. X    dmsg(1,"***************\nProportional\n");
  2391. X    ow->doc->propwidth= (u_short *)win->RPort->Font->tf_CharSpace;
  2392. X    ow->doc->propwidth= ow->doc->propwidth-lowc;
  2393. X    dmsg(1,"Spaceing=%ld\n",win->RPort->TxSpacing);
  2394. X    i=TextLength(win->RPort,test,7);
  2395. X    j=0;
  2396. X    for(k=0;k<7;k++) {
  2397. X        dmsg(1,"'%lc'=%ld.\n",test[k],ow->doc->propwidth[test[k]]);
  2398. X        j+=ow->doc->propwidth[test[k]];
  2399. X    }
  2400. X    dmsg(1,"i=%ld, j=%ld.\n",i,j);
  2401. X    }
  2402. X
  2403. X    ow->scroll=vertbar;
  2404. X    ow->down=downarrow;
  2405. X    ow->up=uparrow;
  2406. X    ow->icon=icon;
  2407. X    myproc->pr_WindowPtr=(APTR)tmpwindow;
  2408. X
  2409. X    /* Set Minimum window limits to reasonable values */
  2410. X#ifdef DEBUG1
  2411. X    dmsg(1,"Window borders: LEFT=%ld, TOP=%ld, RIGHT=%ld, BOT=%ld, TxWidth=%ld, TxHeight=%ld.\n",
  2412. X    borderLEFT,borderTOP,borderRIGHT,borderBOT,win->RPort->TxWidth,win->RPort->TxHeight);
  2413. X#endif
  2414. X
  2415. X#ifdef DEBUG1
  2416. X    dmsg(1,"Setting limits to (%ld, %ld, %ld, %ld)==",
  2417. X    borderLEFT+borderRIGHT+win->RPort->TxWidth*20,
  2418. X    borderTOP+borderBOT+win->RPort->TxHeight*3,
  2419. X    0,
  2420. X    0
  2421. X    );
  2422. X#endif
  2423. X    test=WindowLimits(win,
  2424. X    borderLEFT+borderRIGHT+win->RPort->TxWidth*20,
  2425. X    borderTOP+borderBOT+win->RPort->TxHeight*3,
  2426. X    0,
  2427. X    0
  2428. X    );
  2429. X#ifdef DEBUG1
  2430. X    dmsg(1,"%ld.\n",test);
  2431. X#endif
  2432. X#ifdef DEBUG1
  2433. X    dmsg(1,"Window dimensions are %ld, %ld\n", win->Width, win->Height);
  2434. X#endif
  2435. X#ifdef DEBUG1
  2436. X    dmsg(1,"Window limits are %ld, %ld, %ld, %ld.\n",
  2437. X    win->MinWidth, win->MinHeight, win->MaxWidth, win->MaxHeight
  2438. X    );
  2439. X#endif
  2440. X    ow->saveminwidth=win->MinWidth;
  2441. X    ow->saveminheight=win->MinHeight;
  2442. X    ow->Width=win->Width;
  2443. X    ow->Height=win->Height;
  2444. X
  2445. X    makemenu(win);
  2446. X    return(win);
  2447. X
  2448. Xfail:
  2449. X    if(vertbar) {
  2450. X    if(vertbar->SpecialInfo) FreeMem(vertbar->SpecialInfo,sizeof(struct PropInfo));
  2451. X    if(vertbar->GadgetRender) FreeMem(vertbar->GadgetRender,sizeof(struct Image));
  2452. X    FreeMem(vertbar,sizeof(struct Gadget));
  2453. X    }
  2454. X    if(uparrow) {
  2455. X    if(uparrow->GadgetRender) FreeMem(uparrow->GadgetRender,sizeof(struct Image));
  2456. X    uparrow->GadgetRender=0;
  2457. X    FreeMem(uparrow,sizeof(struct Gadget));
  2458. X    }
  2459. X    if(downarrow) {
  2460. X    if(downarrow->GadgetRender) FreeMem(downarrow->GadgetRender,sizeof(struct Image));
  2461. X    downarrow->GadgetRender=0;
  2462. X    FreeMem(downarrow,sizeof(struct Gadget));
  2463. X    }
  2464. X    if(icon) {
  2465. X    if(icon->GadgetRender) FreeMem(icon->GadgetRender,sizeof(struct Image));
  2466. X    icon->GadgetRender=0;
  2467. X    FreeMem(icon,sizeof(struct Gadget));
  2468. X    }
  2469. X    if(windowcount==0 && screen ) {
  2470. X    CloseScreen(screen);
  2471. X    screen=0;
  2472. X    }
  2473. X    return 0;
  2474. X}
  2475. SHAR_EOF
  2476. echo "End of archive 3 (of 3)"
  2477. # if you want to concatenate archives, remove anything after this line
  2478. exit
  2479.